When I submit a text field into user_items I want it to take the ID of that item from master_list_items and place it into the master_list_items_id column under user_items
I have added master_list_items.rb — but I’m not sure of the relationship to add..
Any suggestions?
master_list_items
+----------------------+----+
| name | id |
+----------------------+----+
| Item A | 1 |
| Item B | 2 |
| Item C | 3 |
+----------------------+----+
user_items
+---- +----------+----------------------+
| uid | item | master_list_item_id |
+-----+----------+----------------------+
| 2 | Item A | NULL |
| 7 | Item C | NULL |
| 9 | Item C | NULL |
+-----+----------+----------------------+
I’m going to guess your models are done like this:
To implement what you’re looking for the solution would probably be like this:
This should yield the results you’re looking for.
For more on relationships refer to the associations module on ActiveRecord.