activerecord - association data in rails model scope -


I have a model posted (blog post) and a model named category . Each term is related_to a category. Each category has a feature called holder , which specifies the amount of time before "ending", for example movies_category.retainer = 30.days

What am I trying to do that is preparing a scope for the post which searches for all the posts that have been "expired" for example, suppose I hardcoded the value of 30.days and it takes up all the categories (hence all the posts) The scope would have been:

  scope: expired, lambda {where ("post.ctated_t   

However, instead of hardcoding, value 30.days , I want to get the value of the holder from the post category and base it on the basis of something like that :

  scope: expired, lambda {where ("post.ctated_t <", time.news-category.retainer}}   

Then put it in words: I have to admit all the posts The end is to be finished, and the status of the term is determined by the retireer value of each post category (i.e. posts in the category of films in 10 days, post in the games category in 5 days) etc.

Is this possible? Do I need some type of join or something?

  scope: expired, lambda {| Retainer | Where ("posts.created_at & lt ;?", Time.now - retainer)}   

Then just like it:

  Post.expired ( Post category classifier) ​​  

or range from model like:

  def post post. Expiry term    

Comments