populateModel composeRelationships help!

I’m trying to figure out how to get data from a form to populate to the table in a one-to-many relationship.

Cart {

one-to-many relationship to cartItem called items

CartItem {

Form on webpage with

<input name=“items.{primaryKeyOfCartItems}.quantity” value="3>

the data is submitted to the handler which does a populateModel
populateModel( model=cart, composeRelationships=true );

But it never updates the one-to-many’s quantity value.

Am I doing something wrong?

composeRelationships is basically used to take foreign keys and turn them into proper relationships. For example, let’s say you submit your form with the following data:

CartID: 3,
Items: [ 41, 32, 21 ],


In this example, it would update Cart to have relationships to Item 41, Item 32, and Item 21. So it’s really a convenience method of looking up an id/guid/whatever into the actual entity so that the relationship can be properly composed when persisting the entity data. If you need to update the value in the actual relationship (e.g., in the existing Item entity), you’ll need to do that separately. However, that’s a pretty interesting idea for adding into populate…

Gotcha makes complete sense! - And yes I’d love to see that idea happen :smiley: Populating sub table data via some specific naming convention [relationshipName].[primaryKey].[fieldName] = value of fieldName and having it populate.

You could also handle multi-relationship update as well using something like [rootEntity].[rootPrimaryKey].[relationshipName].[primaryKey].[fieldName] = value of fieldName

so having a speadsheet of data if you will with multiple inputs in rows & columns could be updated via a single populateModel command.

Just a thought :slight_smile:

I was wondering if updating/inserting data inside the relationship was possible using populateModel(). Would be awesome if this could be implemented into the function.
Just had a quick glance at the BeanFactory.cfc, I think this is where the populateModel Function is in, but since I am new to this framework and OO in particular I am not confident enough to play around with this.

If anyone would be willing to try it out, please share the code and the results :slight_smile:

  • Julian

i got the one-to-many relationship to work last night with updating data. inserting is a different animal. i’ll figure out how to share the code with Luis if he wants to incorporate it.

Could you share the code here? Am curious how this works.