ruby on rails - Sorting on association with has_many_through relation -
i want sorted result using price.
i want result sorting order price when
hotel.packages
i have 2 models(hotel , package )
has_many :through
relationship. both connected each other through relationship , model name package_price
hotel model is:
class hotel < activerecord::base has_many :package_prices, :dependent => :destroy has_many :packages, :through => :package_prices, :order => 'package_prices.price' end
package model is:
class package < activerecord::base has_many :package_prices, :dependent => :destroy #foreign key package_id has_many :hotels, :through => :package_prices, :order => 'package_prices.price' end
package_price model is:
class packageprice < activerecord::base belongs_to :package belongs_to :hotel end
package_prices table fields:
+------------+--------------+------+-----+---------+----------------+ | field | type | null | key | default | | +------------+--------------+------+-----+---------+----------------+ | id | int(11) | no | pri | null | auto_increment | | package_id | int(11) | yes | | null | | | price | int(11) | yes | | null | | | hotel_id | varchar(255) | yes | | null | | | created_at | datetime | no | | null | | | updated_at | datetime | no | | null | | +------------+--------------+------+-----+---------+----------------+
i want packages of hotel sorted price.
Comments
Post a Comment