DataMapper와 조건부 연결을 만들 수 있습니까? 예를 들어DataMapper에는 조건이있는 n이 있습니다.
:
I은 사용자가 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
나는이 만들어 가능할 것이다 것을 알고를 Developer :: User와 그 클래스에서 User의 하위 클래스 인 has n
을 사용합니다.하지만 연관 선언에 직접 적용 할 수 있는지 알고 싶습니다.
또한 ARn을 사용할 때 내가 관리했던 또 다른 방법은 연결을 확장하고 각 작업에 대한 메서드를 다시 작성하는 것이 었습니다.
그래서 확장 모듈에 나는 이런 식으로 뭔가 할 수 :
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
을 그러나 다시, 난 정말이 솔루션을 가능하면 사용을 피하기 위해 싶지만, 그것은 빠른을 수행 할 수 그냥 경우 순간 미리
안녕 댄, 관심과 지원을 주셔서 대단히 감사합니다, 그 정말 감사 : 내가 언급 한 이러한 방법을 시도합니다,하지만이게 내 문제를 해결할 것이라고 확신 :) 다시 한 번 감사드립니다 – zanona