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
update `products`SET `price_gross` = 2,
update `products`SET `price_gross` = 2,
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
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
product
model has a
prices
prices
relationship to the
product_prices
product_prices
table, then your form field for gross_price would probably be FieldType::
make('prices.gross_price')
make('prices.gross_price')
and then the update would be saved to that relationship