F
Filament11mo ago
Stefan

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
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 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 relationship
Jump to solution
4 Replies
Solution
DrByte
DrByte11mo ago
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 relationship
DrByte
DrByte11mo ago
If 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
Stefan
StefanOP11mo ago
thanks!
Want results from more Discord servers?
Add your server