I have the following models:
Users (id, name, email, instance_id, etc…)
Instances (id, domain name)
Books (id, name, user_id, instance_id)
In Rails 3, When a new book is created, I need the user_id, and instance_id to be populated based on the current_user.
Currently, user_id is being assigned when I create a new book but not instance_id? What needs to happen in rails to make that field get filled out on book creation?
Also, shouldn’t rails be error’ing given that I can create books without that instance_id filled out?
thxs
It looks like you have de-normalized
UserandBookmodels by adding reference toInstancemodel. You can avoid the redundant reference unless you have a specific reason.I would rewrite your models as follows:
Now to create a new book for a user.
To get a list of the books belonging to user’s instance:
To get a list of the books created by the user:
Make sure you index the
instance_idcolumn inuserstable anduser_idcolumn inbookstable.