私のプロジェクトには 2 つのモデル クラスがあります。最初はUser
:
class User < ActiveRecord::Base
attr_accessible :email, :name
has_many :micropost1s
end
もう一つはMicropost1
class Micropost1 < ActiveRecord::Base
attr_accessible :content, :user_id
belongs_to :user
validates :content, :length => { :maximum => 140 }
end
私はどこが間違っているのかわかりません。まず、変数を割り当てるために次のコマンドを実行しますfirst_user
。
first_user = User.first
その後、コンソールに次のように記述します。
first_user.micropost1s
私はこのエラーログを取得しています:
Micropost1 Load (0.3ms) SELECT "micropost1s".* FROM "micropost1s" WHERE "micropost1s"."user_id" = 1
SQLite3::SQLException: no such column: micropost1s.user_id: SELECT "micropost1s".* FROM "micropost1s" WHERE "micropost1s"."user_id" = 1
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: micropost1s.user_id: SELECT "micropost1s".* FROM "micropost1s" WHERE "micropost1s"."user_id" = 1
from /var/lib/gems/1.8/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:91:in `initialize'
from /var/lib/gems/1.8/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:91:in `new'
from /var/lib/gems/1.8/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:91:in `prepare'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/sqlite_adapter.rb:246:in `exec_query'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `log'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/sqlite_adapter.rb:242:in `exec_query'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/sqlite_adapter.rb:467:in `select'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/querying.rb:38:in `find_by_sql'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/explain.rb:40:in `logging_query_plan'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/querying.rb:37:in `find_by_sql'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/relation.rb:171:in `exec_queries'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/relation.rb:160:in `to_a'
... 5 levels...
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/associations/collection_proxy.rb:44:in `__send__'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/associations/collection_proxy.rb:44:in `load_target'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/associations/collection_proxy.rb:87:in `method_missing'
from /usr/lib/ruby/1.8/irb.rb:310:in `output_value'
from /usr/lib/ruby/1.8/irb.rb:159:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:271:in `signal_status'
from /usr/lib/ruby/1.8/irb.rb:155:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:154:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:71:in `start'
from /usr/lib/ruby/1.8/irb.rb:70:in `catch'
from /usr/lib/ruby/1.8/irb.rb:70:in `start'
from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start'
from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start'
from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands.rb:41
from script/rails:6:in `require'
from script/rails:6irb(main):008:0>