ユーザーが日付とそれらの日付に関連する興味を入力できるアプリがあります。興味と場所に基づいた取引を (日付の数日前に電子メールで) 送信する必要があります。すべてのモデルをセットアップしてデータを適切に記録しましたが、モデルに日付をクエリして、都市と興味に基づいて適切な取引を送信する方法を考えています。
ノート:
*各都市とインタレスト カテゴリには 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