質問

これに頭を包むことはできません...

class User < ActiveRecord::Base
  has_many :fantasies, :through => :fantasizings
  has_many :fantasizings, :dependent => :destroy
end

class Fantasy < ActiveRecord::Base
  has_many :users, :through => :fantasizings
  has_many :fantasizings, :dependent => :destroy
end

class Fantasizing < ActiveRecord::Base
  belongs_to :user
  belongs_to :fantasy
end

...それは私の主要な関係では正常に機能します。 User できる 持ってる たくさんの Fantasies, 、そしてそのa Fantasy できる 属する 多くの人に Users.

ただし、別の関係を追加する必要があります 好み (ように、a User 「いいね」a Fantasy 「持っている」のではなく... Facebookとあなたが「壁のポスト」を「好きではない」と考えてください。目的)。

私は別の協会を作るべきだと私は集めましたが、私はそれをどのように使用するか、またはこれが正しいアプローチでさえあるかどうかについて少し混乱しています。以下を追加することから始めました。

class Fantasy < ActiveRecord::Base

  ...

  has_many :users, :through => :approvals
  has_many :approvals, :dependent => :destroy
end

class User < ActiveRecord::Base

  ...

  has_many :fantasies, :through => :approvals
  has_many :approvals, :dependent => :destroy
end

class Approval < ActiveRecord::Base
  belongs_to :user
  belongs_to :fantasy
end

...しかし、どのようにして協会を作成することができますか Approval 通りではなく Fantasizing?

誰かがこれをまっすぐに私を設定できれば、私は多くの義務を負うでしょう!

役に立ちましたか?

解決

最初のコードセットを保持し、ユーザーモデルに追加します。

has_many :approved_fantasies, :through => :fantasizings, :source => :fantasy, :conditions => "fantasizings.is_approved = 1"

空想のテーブルに、IS_APTROVED BOOLEANフィールドを追加します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top