SELECT `subscriptions`.*, DATE_ADD(`subscriptions`.created_at, INTERVAL `packages`.validity DAY) as end_date
FROM `subscriptions` INNER JOIN `packages` ON `packages`.`id` = `subscriptions`.`package_id`
order by end_date;
views:
37answers:
1
A:
Assuming you have a model Subscription that is a subclass of ActiveRecord::Base Then it is simply just
Subsccription.select("subscriptions
.*, DATE_ADD(subscriptions
.created_at, INTERVAL packages
.validity DAY) as end_date).joins(:packages).order(:end_date)
I may have some syntax wrong, such as it may be :package not :packages. But the basic
Olives
2010-10-14 16:28:10