activerecord - Rails using 'where' to search association -
i want select notices
belong character
via has_one
association have nil
supernotice
. how code this?
notice.rb:
belongs_to :character has_one :active_comment_relationship, class_name: "commentrelationship", foreign_key: "commenter_id", dependent: :destroy has_one :supernotice, through: :active_comment_relationship, class_name: "notice", source: :commentee accepts_nested_attributes_for :active_comment_relationship has_many :passive_comment_relationships, class_name: "commentrelationship", foreign_key: "commentee_id", dependent: :destroy has_many :comments, through: :passive_comment_relationships, class_name: "notice", source: :commenter
character.rb:
has_many :notices def topnotices self.notices.where(supernotice: nil) # doesn't work end
logs:
: select "notices".* "notices" "notices"."character_id" = $1 , "notices"."commentee_id" null order "notices"."created_at" desc completed 500 internal server error in 316ms (activerecord: 12.0ms) activerecord::statementinvalid (pg::undefinedcolumn: error: column notices.commentee_id not exist line 1: ..."notices" "notices"."character_id" = $1 , "notices"....
the logs show error notices.commentee_id
not exist, i've stated in notice.rb
notice has_one :supernotice through: :active_comment_relationship
. going wrong?
you need add:
has_many :notices
in character
model.
Comments
Post a Comment