I had a problem visiting my database using seed.rb , in particular where the table relationships are related.
Here is a sample code:
# seed.rb user = User.find_or_create_by_login( :login => "myname", :email => " myname@gmail.com ", :user_type => "Admin", :password => "admin", :password_confirmation => "admin") project = Project.find_or_create_by_user_id( :user_id => user.id, :name => "Test Project")
When the project is created (along with other unrelated parameters that I did not consider above), user_id is empty. How can I make this work?
This is the strangest behavior I have seen in everything that is so simple. About eight tables have been created in my seed file, and some of them are nested at 3-4 levels (i.e. users have several projects, projects have several tasks, etc.).
When I call user user as above and the user.id link several times after that, it only works once! I tried adding [user.reload] before creating each new entry, but to no avail. I do not think that this will make sense to everyone, but are there any opportunities here? Thanks to everyone.
source share