views:

37

answers:

1
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;
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