Okay, so I have this:

    class Team < Sequel::Model
      many_to_many :users

      many_to_many(:admins, class: User, :join_table => :teams_users, 
:right_key => :user_id) do |ds|
        ds.where(Sequel[:teams_users][:role] => 'admin')
      end
    end

Which give me :users and ;admins. #add_user works, however #add_admin does 
the same as #add_user - the where clause in the dataset is not respected.

On Sunday, July 21, 2019 at 1:59:04 PM UTC+1, Matthew Gibbons wrote:
>
> I'm not sure if this is the right way to go about this, but I have two 
> tables Users and Teams, with the following join table:
>
>     class CreateTeamsUsers < Sequel::Migration
>       def up
>         create_table :teams_users do
>           foreign_key :team_id, :teams
>           foreign_key :user_id, :users
>           
>           column :role, String
>     
>           primary_key [:team_id, :user_id]
>         end
>       end
>     end
>
>     class Team < Sequel::Model
>       many_to_many :users
>     end
>
>     class User < Sequel::Model
>       many_to_many :teams
>     end
>
> The :role column specifies the role of the user as a member of the team, 
> i.e. it could be "Owner", "Admin", "Guest", etc. 
>
> I can't see how I can get access to the :role column for querying. I'd 
> like to be able to select all team administrators, for example:
>
>     Team[1].admins
>     => [#<User @values={:id=>1}>, ...]
>
> Any help or advice gratefully received! ;-)
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/8d99601d-4476-4d5f-a457-a83b902cafb2%40googlegroups.com.

Reply via email to