jeudi 16 avril 2015

Rails - Populate fields in table with a join

I have two models - product and orders. I have a bunch of orders already. I did a migration to add the product name and sku to the order table. So when there is a new order, the order table populates with the product name and sku. This happens in the controller when a new order is created.


For the older orders, those new columns are blank. How do I do a join to the product table and populate the older orders with the product name and sku? There is a product_id foreign key in the order table.


I'm using SQLite and I presume this will be done via the rails console.


Aucun commentaire:

Enregistrer un commentaire