私の問題を説明しましょう:
私は2つのモデルを持っています:
class User < AR::Base
has_many :contacts
end
class Contact < AR::Base
belongs_to :user
belongs_to :user_contact_id, :class_name => "User", :foreign_key => "user_contact_id" # The "contact" is an ID from the table user.
def self.is_contact?(user_contact_id)
# CHECK IF THE RECORDS EXIST VIA DB OR CACHE OR WHATEVER #
end
end
User のインスタンスを @user として持つと、is_contact? を確認できます。このような:
@user.contacts.is_contact?(a_user_id)
これは完全に機能します。私の問題は、is_contact? 内の @user の属性にアクセスしたいということです。お問い合わせの方法。
これは可能ですか?
皆さんに感謝します。