このクエリの作成方法に頭を悩ませています。一連のスコープを作成してそれらを連鎖させようとする必要があるかどうかはわかりません。それともクラスメソッドに入れますか?または、両方のコンボを行いますか?誰かが私に短い例を与えることができれば、それは私が窓から飛び出すのを妨げるでしょう.私はこれに1週間以上取り組んできました.
class CensusDetail < ActiveRecord::Base
belongs_to :apartment
belongs_to :resident
end
class Apartment < ActiveRecord::Base
belongs_to :apartment_type
has_many :census_details
has_many :residents, :through => :census_details
end
class ApartmentType < ActiveRecord::Base
has_many :apartments
end
class Resident < ActiveRecord::Base
has_many :census_details
has_many :apartments, :through => :census_details
end
apartment.rent_ready = boolean value if apartment is ready
apartment_type.occupany = the number of allowed occupants in an apartment
census_detail.status = either "past", "present", or "new"
census_detail.moveout_date = date time resident is scheduled to move out
次のことを行うクエリを作成する必要があります。
- if the apartment is rent ready then do the following:
- pull a list from census_details of all residents set as "current" for each apartment
-if the # of residents is less than the value of apartment_type.occupancy for this
apartment, then list it as available
-if the # of residents is = to the value of apartment_type.occupancy then
-does any resident have a scheduled move out date
-if not, do not list the apartment
-if yes, then list apartment
ヘルプや提案をお寄せいただきありがとうございます。