2009/9/3 Daniel Drehmer <[email protected]>:
>
> The only thing that remains unknown to me is how query the list of
> users of a given sandbox that have the role "donkey". Is it possible
> to use the find method the rails way, without "injecting" sql?
Yes of course, you should very rarely find yourself using sql. If you
have a Sandbox called @sandbox then the users of that sandbox are
@sandbox.users so those that have the role donkey are
@sandbox.users.find_by_role('donkey')
At least I think you can do that, I prefer to use a named scope rather
than find_by.. So you might have a named scope on User called
by_role(role) that returns the Users with the given role. Then you
would use
@sandbox.users.by_role('donkey')
Or if you often wanted to find the donkeys then you might have a named
scope on User called donkies that finds them and then you could say
@sandbox.users.donkies
Colin
>
>
>
> On 3 set, 16:29, Daniel Drehmer <[email protected]> wrote:
>> Thank you Ar Chron! This is exactly what I was looking for.
>>
>> I appreciate the other answers, but those reading this thread should
>> notice that the case I described could not be solved without this
>> "role" attribute in the participation model.
>>
>> This was the missing piece. Thank you!
>>
>> On 3 set, 13:21, Ar Chron <[email protected]> wrote:
>>
>>
>>
>> > > Any idea of how to approach this?
>>
>> > Sounds like Users, Sandboxes, and Participations - the main point being
>> > a full join table (participation) with additional attributes
>>
>> > User
>> > has_many :participations
>> > has_many :sandboxes, :through => :participations
>>
>> > Sandbox
>> > has_many :participations
>> > has_many :users, :through => :participations
>>
>> > Participation
>> > user_id
>> > sandbox_id
>> > role (which is user, or admin, or donkey, or whatever)
>> > belongs_to :user
>> > belongs_to :sandbox
>>
>> > Or something along those lines...
>> > --
>> > Posted viahttp://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
-~----------~----~----~----~------~----~------~--~---