I'm in section 2.3.3 where we open up the rails console. I'm then able to retrieve the first_user using
first_user = User.first
but I get an error with the next command:
first_user.microposts
Console Message:
> first_user.microposts
Micropost Load (0.4ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = 1
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: microposts.user_id: SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = 1
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:91:in `initialize'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:91:in `new'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:91:in `prepare'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:246:in `block in exec_query'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:242:in `exec_query'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:467:in `select'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/querying.rb:38:in `block in find_by_sql'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/explain.rb:41:in `logging_query_plan'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/querying.rb:37:in `find_by_sql'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/relation.rb:171:in `exec_queries'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/relation.rb:160:in `block in to_a'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/explain.rb:34:in `logging_query_plan'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/relation.rb:159:in `to_a'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:159:in `all'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/associations/collection_association.rb:382:in `find_target'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/associations/collection_association.rb:335:in `load_target'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/associations/collection_proxy.rb:44:in `load_target'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/associations/collection_proxy.rb:87:in `method_missing'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /Users/ryentzer/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Here is what I THINK is happening. I initially tested both the Users and the Microposts by adding, updating, and deleting users and posts. So I think that the micropost is no longer associated with the first user.
But, I don't know how to see which user_id IS associated with the micropost.
I currently have one Micropost:
> Micropost.all
Micropost Load (0.3ms) SELECT "microposts".* FROM "microposts" => [#<Micropost id: 4, content: "Testing", created_at: "2013-06-10 01:24:34", updated_at: "2013-06-10 01:24:34">]
How do I tell which user_id is connected with the micropost?