For the record, this is what I came up with (having dropped the :role
column and replaced with an :admin column of type TrueClass):
class Team < Sequel::Model
many_to_many :users
many_to_many(:administrators,
:class => User,
:join_table => :teams_users,
:right_key => :user_id,
:adder => (
lambda do |user|
user
.db[:teams_users]
.insert_conflict(
:target => [:team_id, :user_id],
:update => {Sequel[:admin] => true}
)
.insert(team_id: id, user_id: user.id, admin: true)
end
),
:remover => (
lambda do |user|
user
.db[:teams_users]
.update(team_id: id, user_id: user.id, admin: false)
end
)
) do |ds|
ds.where(Sequel[:teams_users][:admin] => true)
end
def administrators_include?(user)
!!db[:teams_users].first(team_id: id, user_id: user.id, admin: true)
end
def members_include?(member)
!!db[:teams_users].first(team_id: id, user_id: user.id)
end
end
It probably needs a :clearer fro completeness, but it works very well. I
can add an administrator, and if already a member, it is set as an
administrator (and vice versa). :-)
Thanks again.
On Monday, July 22, 2019 at 8:02:43 AM UTC+1, Matthew Gibbons wrote:
>
> Go it. Thank you. Not just for your response, but also for Sequel and
> Roda. ;-)
>
--
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/8e655215-4c82-4cc9-b6e6-b52fffb3672c%40googlegroups.com.