I'm working in a Wakanda environnement with the angular-wakanda connector.
Assume this model : Employee(firstName,lastName,company) and Company(name)
In the employee form, I have a select input that is filled with companies names (which is a entity collection).
I have set a ng-model="selectedCompany"
in the select
When I select one company and perform a save, the value I get represent the value I have pass in the value of my option (ID or name).
When I assign the value to a new entity using the $create()
method, I don't know which way to set the entity to the relation attribute. I assume that I have to give an entity. The thing is that I already have the entitycollection with all the entities. So I don't see the reason why should I query again the server just to assign somthing that I have already.
So the thing is that we should have a method like $find
or $getById
that will not do a request on the server but get the entity that is already loaded in the entityCollection. For now I use my own method that do a simple loop over my array. (I can share the code if anybody need it)
Am I missing a way to do that?
Assuming your
selectedCompany
variable contains an entity (of type Company), you only have to pass this variable on the$create()
call with the property name like this:If
selectedCompany
contains only company name or ID, it's on you to have an array to map the companies with their name or ID. Something like that:But the simplest way is the first, with your
<select>
directly iterating through entity collection, so that you can deal with entities.Edit: Retrieving object with
ng-option
To get the object on which you iterate on your
select
, you can useng-option
like this:On the controller