why refModel just uses "name" field? - atk4

please see this code:
$this->addField('user_id')->refModel("User");
this search for the "name" field by default! but I want to connect the username field. how can we define which field to be the refrence?

in Model_User
$this->addField('name','username');
See this method:
https://github.com/atk4/atk4/blob/master/lib/SQL/Model.php#L95
but this method is obsolete and you should use hasOne instead of it.
function hasOne($model,$our_field=null,$display_field=null,$as_field=null)

Related

mongoose $literal in find method projection

I have a mongoose find method like this,
photo.find({},{
name:1,
src:1,
likes:{$literal:[]},
dislikes:{$literal:[]},
}).then(photos => ....)
what I want is, when I run the code likes and dislikes field must be an empty array for every record.
I try this way but not working.
Unsupported projection option: likes: { $literal: 1 }
Any idea to add default value for any field in find method ?
As per mongoose, document schema is constructed during its creation. So you can also edit the schema with a default value, so for every record, when it is created it will create likes, and dislikes with empty values.
You can also do this way, if you feel the schema control is not in your hands.
https://mongoosejs.com/docs/2.7.x/docs/defaults.html
photo.find({ 'name' : '1', 'likes': {$ne: []}})

How to get more datas from database in a .tpl file in Prestashop

I'm working on prestashop 1.7.
I added a field to the specific_price table.
I would like to use the data in this field in the cart-detailed-product-line.tpl
How should I do this ?
Do I need to connect to the price_specific table in the Cart.php class?
If yes, how?
Thanks in advance!
Yes, the simplest in view of your situation, is to create an override Link.php, and in there make a call to your table to fetch your information.
In the tpl you only have to put {$link->nameoffunction(parametre)}
Regards
Thanks a lot ethercreation!!
I put in the Link.php :
public static function getSpecificPriceRatioAjout($id_product_attribute)
{
$unit_price_ratio_ajout = Db::getInstance()->executeS(
'SELECT unit_price_ratio_ajout FROM '._DB_PREFIX_.'specific_price WHERE id_product_attribute = '.$id_product_attribute
);
var_dump($unit_price_ratio_ajout);
return $unit_price_ratio_ajout;
}
In my .tpl :
{$link->getSpecificPriceRatioAjout({$product.id_product_attribute})}
The Response: htmlspecialchars() expects parameter 1 to be string, array given
Have you an ideo of what I've done wrong?

How add dynamic user attribute value in keycloak with saml

ENVIRONMENT:
Keycloack 3.2
Saml2.0
SITUATION:
I need to add user attributes value dynamically.
TASK:
I need name attribute for my user, which can fill dynamically from First Name and Last Name fields, which as I found in keycloack can be fullName property.
NOTE: Instead of fullName it can be firstName + lastName field in my case as well.
ACTION:
I added user property with name fullName under my Clients -> myCLient -> Mappers,
then added under my user Users -> myUser -> Attributes, attribute key name and attribute value ${fullName}.
RESULT:
As a result I got ${fullName} as a value instead of dynamic value from my predefined user property.
QUESTIONS:
Is it possible to do this kind of things what I need ?
If it's possible then, what are wrong in my steps here?
For users like me who looking for a solution of this problem with newest version of Keycloak, in keycloak 18.0 you can create a Mapper with the type Javascript Mapper with this code: user.getFirstName() + ' ' + user.getLastName().
As a solution, I found that under client in keylock we have builtin user properties.
Example X500 givenName, X500 surname can be added and can get in BE side as a part of SAML assertion attributes.
There is another solution if the user federation are LDAP or Active Directory
On the user federation you can use the full-name-ldap-mapper.
By default it uses cn, but you can change that.
Next in your client you would add a saml mapper.
{
"name": "fullName",
"protocol": "saml",
"protocolMapper": "saml-user-attribute-mapper",
"consentRequired": false,
"config": {
"attribute.nameformat": "Unspecified",
"user.attribute": "full name",
"friendly.name": "Full name",
"attribute.name": "displayName"
}
}
Remember the attribute.name is the property that the SP would use.
Also the nameformat has to be discussed with the SP.

How to fetch data from couchDB using couch api?

Instead keys and IDs alone, I want to get all the docs via couch api. I have tried with GET "http://localhost:5984/db-name/_all_docs" but it returned
{
"total_rows":4,
"offset":0,
"rows":[
{"id":"11","key":"11","value":{"rev":"1-a0206631250822b37640085c490a1b9f"}},
{"id":"18","key":"18","value":{"rev":"30-f0798ed72ceb3db86501c69ed4efa39b"}},
{"id":"3","key":"3","value":{"rev":"15-0dcb22bab2b640b4dc0b19e07c945f39"}},
{"id":"6","key":"6","value":{"rev":"4-d76008cc44109bd31dd32d26ba03125d"}}
]
}
From the documentation
for the below request it will send the data as we expected but it requires set of keys in request.
POST /db/_all_docs HTTP/1.1
{
"keys" : [
"11",
"18"
]
}
Thanks in advance.
The _all_docs endpoint is actually just a system-level view that uses the _id field as the index. Thus, any parameters that you can use for views also apply here.
If you read the documentation further, you'll find that adding the parameter include_docs=true to your view will include the original documents in the results. The documents will be added as the doc field alongside id, value and rev.

Angularjs + Spring jpa repository Many-to-one field is not saving

I am using Angularjs, Spring jpa repository, hibernate.
The problem is "Unable to save the id of the Customer in the order table."
table names: Order, CustomerGlobal
reference col name for Customer in Order table is customerGlobal_id.
Order belongs to a Customer. Order table has a customerGlobal_id field.
In the Entity (Order), I have defined
#ManyToOne(optional = false) #JsonIgnore
CustomerGlobal customerGlobal;
Order belongs to one Customer. If I specify a JoinColumn, hibernate is generating the column in the database. So, I think there is no issue there.
I have added Getter and Setter for the customerGlobal field.
I am using JPA repository, the interface is defined as follows:
public interface OrderRepo extends JpaRepository<Order, Long>, JpaSpecificationExecutor<Order> {
...
}
I am assuming that this would work fine too.
Here is the relevant part of the html:
<select ng-options="convertToInt(customer.id) as customer.name for customer in c" class="form-control " name="customerGlobal" ng-model="req.customerGlobal" required></select>
This is part of a form which gets saved from the associated controller. The values for c are obtained by get request on load.
[{"id":1,"name":"XYZ","contactPerson":"ABC","mobile":"1111111111","email":"abc#adef.com",}]
This seems to be working fine. I get a dropdown list of the customers in the table.
When I save the form, customerGlobal_id and other field values are sent via POST but the customerGlobal_id does not get saved to the database.
This does not seem to be a very specific problem. This is a basic many-to-one relationship that is not getting saved. I am not completely familiar with Angularjs. So please help me out with this. Thanks in advance.
In order to save a relationship with spring rest, you shouldn't use the id of the entity, but the reference url of the entity. So let's say that you have a Car entity that has an association with a Make entity, and you want to set the make of the car. Here is what you should do:
Step 1. get the Make entity:
-get a specific `Make`: localhost:8080/makes/1
-get a a list of `Make`: localhost:8080/makes
and select the one you want:
{
"name" : "Toyota",
"country" : "Japan",
"_links" : {
"self" : {
"href" : "http://localhost:8080/makes/1"
}
}
Step 2. Now insert / update a Car like this:
POST/PUT http://localhost:8080/cars/123
{
"model" : "Corolla",
"year" : "2006",
"hp" : 95,
"make" : "http://localhost:8080/makes/1"
}
and NOT like this:
{
"model" : "Corolla",
"year" : "2006",
"hp" : 95,
"make" : 1
}
Spring Data Rest understands the reference url of the entity.

Resources