# Polymorphic challenge

**URL:** <https://www.ruby-forum.com/t/polymorphic-challenge/102117>\
**Category:** Rails\
**Created:** [August 11, 2006, 12:41am UTC](https://www.ruby-forum.com/t/polymorphic-challenge/102117 "2006-08-11T00:41:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@sylow](https://www.ruby-forum.com/u/sylow)\
**Post date:** [August 11, 2006, 12:41am UTC](https://www.ruby-forum.com/t/polymorphic-challenge/102117/1 "2006-08-11T00:41:56Z")

</div>

Hello guys,

I have 2 classes (I pasted small part of them here);

class Shop \< ActiveRecord::Base  
has\_many :items, :as=\> :itemable

protected  
def self.paying\_scope  
with\_scope(:find =\> {:conditions =\> ‘expires\_on \> NOW()’, :include  
=\> [:address]}) do  
yield  
end  
end  
end

class Item \< ActiveRecord::Base  
belongs\_to :itemable, :polymorphic =\> true  
end

Shops has expires\_on field which I check if they can be shown or not  
during searches =\> NO PROBLEM

I need to do same think for items, if a shop subscription (=expires\_on)  
is expired then I wanna exclude that item from search.

What is the elegant way to solve it?

Thanks in advance

PS: I use [http://rubyforge.org/projects/ez-where/](http://rubyforge.org/projects/ez-where/) for my searches.

Gokhan
