У меня есть эти модели, но когда я делаю Message.last.people или Message.last.recipient_lists, я получаю сообщение об ошибке. Как я могу ссылаться на списки получателей или людей, прикрепленных к сообщению с активной записью? Нужно ли мне делать RecipientList.where(:message => Message.last)
? Кажется, должен быть лучший способ сделать это через .message?
class Message < ActiveRecord::Base
has_many :people, through: :recipient_list
end
class Person < ActiveRecord::Base
has_many :messages, through: :recipient_list
end
class RecipientList < ActiveRecord::Base
belongs_to :person
belongs_to :message
end
я получаю эту ошибку
Message.last.recipient_lists
Загрузка сообщения (0,7 мс) SELECT "messages".* FROM "messages" ORDER BY "messages"."id" DESC LIMIT 1 NoMethodError: неопределенный метод `recipient_lists' дляиз /home/nick/.rvm/gems/ruby-2.0.0-p598/gems/activemodel-4.0.9/lib/active_model/attribute_methods.rb:439:in
method_missing' from /home/nick/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.0.9/lib/active_record/attribute_methods.rb:168:in
method_missing' from (irb):1 from /home/nick/.rvm/gems/ruby-2.0.0-p598/gems/railties-4.0.9/lib/rails/commands/console.rb:90:instart' from /home/nick/.rvm/gems/ruby-2.0.0-p598/gems/railties-4.0.9/lib/rails/commands/console.rb:9:in
start' из /home/nick/.rvm/gems/ruby-2.0.0-p598/gems/railties-4.0.9/lib/rails/commands.rb:62:in<top (required)>' from bin/rails:4:in
require' из bin/rails:4:in `'Message.last.people Загрузка сообщения (1,0 мс) ВЫБЕРИТЕ «сообщения».* ИЗ «сообщений» ORDER BY «messages». «id» DESC LIMIT 1 ActiveRecord::HasManyThroughAssociationNotFoundError: Не удалось найти ассоциацию: recipient_list в модели Сообщение
nil
шансе? - person David Hoelzer   schedule 23.07.2015