我有一个应用程序,可让用户输入与这些日期相关的日期和兴趣。我需要根据他们的兴趣和位置向他们发送交易(日期前几天 - 通过电子邮件)。我已经正确设置了所有模型并记录了数据,只是想知道如何查询模型的日期,然后根据城市和兴趣发送适当的交易。
笔记:
*每个城市和兴趣类别只有1个交易
*对于日期类型(假期、场合、朋友生日等),我有几种不同的模型。所有的结构都几乎相同。
*每种日期的所有兴趣都存储在 person_interests 中。
Models:
Class User
belongs_to :province
belongs_to :city
has_many :friends_bdays
has_many :occasions
has_many :person_interests, :as => :person
has_many :interests, :through => :person_interests
has_many :user_holidays
has_many :holidays, :through => :user_holidays
has_many :anniversaries
end
class Deal < ActiveRecord::Base
belongs_to :interest
belongs_to :city
belongs_to :store
end
class Store < ActiveRecord::Base
has_many :deals
belongs_to :city
belongs_to :province
end
class PersonInterest < ActiveRecord::Base
belongs_to :interest
belongs_to :person, :polymorphic => true
end
class Interest < ActiveRecord::Base
has_many :person_interests
has_many :deals
end
class Occasion < ActiveRecord::Base
belongs_to :user
belongs_to :admin_user
has_many :person_interests, :as => :person
has_many :interests, :through => :person_interests
end
class Anniversary < ActiveRecord::Base
belongs_to :user
has_many :person_interests, :as => :person
has_many :interests, :through => :person_interests
end
class Friend_bday < ActiveRecord::Base
belongs_to :user
has_many :person_interests, :as => :person
has_many :interests, :through => :person_interests
end