ひょっとして、DataMapper で条件付き関連付けを作成することは可能ですか?
例えば:
そのユーザーが属性を持っている場合にのみ、ユーザーにn個のアプリを持たせたい:developer => true
このようなもの:
class User
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :nullable => false
  property :screen_name, String, :nullable => false, :unique => true
  property :email, String, :nullable => false, :unique => true, :format => :email_address
  property :password, BCryptHash, :nullable => false
  property :developer, Boolean, :default => false
  #The user just gets apps if developer
  has n :apps #,:conditions => "developer = 't'"
end
class App
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :nullable => false
  belongs_to :user
end
User から Developer::User としてサブクラスを作成し、そのクラスで を使用することでこれがhas n可能になることはわかっていますが、関連宣言で直接作成できるかどうかを知りたいです。
ARn を使用するときに私が何とかできたもう 1 つの方法は、関連付けを拡張し、各アクションのメソッドを書き直すことでした。
したがって、拡張モジュールでは、次のようなものを使用できます。
module PreventDeveloperActions
  def new
    if proxy_owner.developer?
       super
    else
       raise NoMethodError, "Only Developers can create new applications"
    end
  end
 # and so on for all the actions ...
end
しかし、繰り返しになりますが、可能であればこのソリューションの使用を避けたいと思いますが、DataMapper を使用して迅速かつ直接的な方法を簡単に実行できる場合に限ります :)
前もって感謝します