2009/4/1 Fernando Perez <[email protected]>

>
> Hi,
>
> I have 3 models: User, Order(user_id), Membership(order_id).
>
> I'd like to know if a given user has a valid membership, i.e: the
> order.status == 'paid' and membership.expires_at > Time.now
>
> I could use a User has_many memberships :through => :order, and put a
> condition but that adds membership and order logic to the User model
> which I don't want.
>

I would always, as a first solution, look at what the question being asked
is.  You want to know if 'a given user has a valid membership', therefore
use the User has_many memberships option, I would not try to turn the
question on it's head to answer it.


> So my idea is to add a redundant user_id to membership, and to set an
> expires_at for a membership only when the order gets paid. This way I
> can't easily query and it keeps the encapsulation of each model where it
> belongs to.
>
> What do you think?
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to