I have a User model and a Subscription model. The Subscription model
contains, among other things, a foreign key that points back to User
(user_id) and a Boolean (active) that specifies whether the Subscription is
active or inactive. There can only be one active Subscription for a User at
any time, though there may be multiple canceled/inactive Subscriptions for
that user. I'd like to specify an association for the User model that grabs
the first active, associated Subscription (which, because of other measures
I've taken will be the ONLY active, associated Subscription). I can almost
get there with the following in the User model:
one_to_one :subscription, :class=>'DonorSee::Subscription',
:order=>:active, :limit=>1
However, this returns the first *inactive* Subscription, since false orders
before true. I want the first *active* Subscription. I've tried the
following:
one_to_one :subscription, :class=>'DonorSee::Subscription',
:reverse_order=>:active, :limit=>1
but I still get the first inactive Subscription when I invoke
user.subscription:
Here are my models (simplified):
class Subscription < Sequel::Model
many_to_one :user
end
class User < Sequel::Model
one_to_one :subscription, class: 'DonorSee::Subscription',
:reverse_order=>:active, :limit=>1
end
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.