samedi 6 janvier 2018

Select expired and not expired values MySQL, Rails 5

I have Ruby on Rails 5 with MySQL app. I have table products and table subscription with the standard Rails 5 datetime column - created_at'.

The model Product has_many :subscriptions and the model Subscription belongs_to :product.

I want to select all subscriptions for a product that are created before for the example 1 day and all products that are created (for the example last 24 hours) in this way that I can use them like this - product.expired_subscriptions and product.active_subscriptions.

Aucun commentaire:

Enregistrer un commentaire