2012-06-19 43 views
0

进出口设立是通过电子邮件发送的交易相对于一个人的利益,并提醒服务城市..基本上,用户输入重要的日期(朋友BDAY,周年ECT)和特殊的人的利益。正确Rails的关联安装

我想送他们的交易基于1)用户城市和2)相关人员

的利益应该如何设置我协会的交易模式?

我有什么至今..

class User < ActiveRecord::Base 
belongs_to :city 
has_many :person_interests, :as => :person 
has_many :interests, :through => :person_interests 

end 

class City < ActiveRecord::Base 
attr_accessible :name 
    belongs_to :province 
    has_many :users 
end 

class PersonInterest < ActiveRecord::Base 
    belongs_to :interest 
    belongs_to :person, :polymorphic => true 
end 

class Interest < ActiveRecord::Base 
    has_many :person_interests 
end 

谢谢!

+0

到目前为止你有什么?什么不起作用或对你来说不理想? – rfunduk

+0

@rfunduk添加了什么我已经有..一切都很好,并收集我需要精细的信息..只是不知道如何与利益,城市的新的交易模式相关联。 – js111

+0

交易会成为既兴趣又适合城市的belongs_to? – js111

回答

1

如果交易可以适用于多个兴趣,你会开始喜欢的东西:

class Deal < ActiveRecord::Base 
    belongs_to :interests 
    belongs_to :city 
end 

class City < ActiveRecord::Base 
attr_accessible :name 
    belongs_to :province 
    has_many :users 
    has_many :deals 
end 

class Interest < ActiveRecord::Base 
    has_many :person_interests 
    has_many :deals 
end 

然后你就可以做类似

@relevant_deals = @city.deals.where(:interest_id => 'abc') 

@relevant_deals = @interest.deals.where(:city_id => 'def') 
+0

谢谢!我真的不关心,如果这笔交易可以属于一个以上的利息或不...任何设置更容易..我不具有管理员增加了交易多次,如果它需要一个以上的利率关联的头脑...... – js111

+0

这样的话它将如何在城市和兴趣模型工作...例如,在城市(一)可以有利息的交易(一)和市(b)将有不同的交易利息(一) – js111

+0

哦确定得到it..do你认为我需要的has_many:通过? – js111