ruby - DRYing my has_many's in Rails -
I have an ideal class in which, among other things:
class group & Lt; ActiveRecord :: Base has has_many: membership has_many: users ,: through = & gt; : Membership has_many: admins ,: through = & gt; : Membership ,: Source = & gt; : User, terms => "Subscriptions.role = # {ROLES [: Admin}}" is_main: Subscriber, via = & gt; : Membership ,: Source = & gt; : User, terms => "Subscriptions.role & gt; = # {Rolls [: Customer]}" is: Medium: Writer, via = & gt; : Membership ,: Source = & gt; : User, terms => "Subscriptions.role & gt; = # {Rolls [: Author]}" is_maya: Pending_assists ,: By & gt; : Membership ,: Source = & gt; : User, terms => "Subscription.pending = true" end
Number of times : through = & gt; : Membership ,: Source = & gt; : Users repeatedly bother me. I know the route files, you can do
map.with_options
. Is there something like this for my model associations?
with_upus
is actually one on the extension, so that you can call it your ActiveRecord :: Base can also be used in
with_options: through = & gt; : Membership ,: Source = & gt; : What user? Obj | Obj.has_many: Administrator, terms = & gt; "Subscriptions.role = # {Rolls [: Admin]}" obj.has_many: Subscriber ,: Conditions => "Subscriptions.role & gt; = # {Rolls [: Customer]}" obj.has_many: Authors, terms = & gt; "Subscriptions.role & gt; = # {Rolls [: Author]}" obj.has_many: Pending_sales ,: conditions => "Subscriptions.bandending = true" end
Comments
Post a Comment