update relative table
I have a product resource class where in the main form I have only fields that belongs to the products table and all updates go fine.
Now, if I add two more fields to the main form, like gross_price, net_price. I want to store them in a table named product_prices.
When I try to update the price fields that are the product_prices table, I get an error
It tries to update the products table and not the product_prices table.
What to do in order to be able to also update the relative tables when I update any of the fields in the form?
Thanks in advance!
Solution:Jump to solution
If the fields are from a table with relationships defined, then the field name in the form would need to take the form of "relationshipname"(dot)"fieldname". So, if your
product
model has a prices
relationship to the product_prices
table, then your form field for gross_price would probably be FieldType::make('prices.gross_price')
and then the update would be saved to that relationship4 Replies
Solution
If the fields are from a table with relationships defined, then the field name in the form would need to take the form of "relationshipname"(dot)"fieldname". So, if your
product
model has a prices
relationship to the product_prices
table, then your form field for gross_price would probably be FieldType::make('prices.gross_price')
and then the update would be saved to that relationshipIf you're already "doing" that, then please post the code for your models' relationships and for your form, and any methods you've overridden for manipulating data or queries for saving and retrieving
thanks!