Replies: 3 comments 5 replies
-
This is expected. This is documented in |
Beta Was this translation helpful? Give feedback.
-
This works for me: DB.extension :pg_array
Sequel.extension :pg_array_ops
GRAPH_BLOCK = proc do |j,lj,js|
Sequel.pg_array_op(Sequel[j][:groups]).contains(Sequel.pg_array(['main_manager'], :enum_groups))
end
class Carrier < Sequel::Model
one_to_one :account, class: :Account, graph_block: GRAPH_BLOCK do |ds|
ds.with_group('main_manager')
end
end
class Partner < Sequel::Model
one_to_one :account, class: :Carrier, graph_block: GRAPH_BLOCK do |ds|
ds.with_group('main_manager')
end
end
class Account < Sequel::Model
many_to_one :carrier
many_to_one :partner
dataset_module do
def with_group(group)
where(some conditions)
end
end
end
puts Carrier.association_left_join(account: :partner).sql
# SELECT * FROM "carriers"
# LEFT JOIN "accounts" AS "account"
# ON (("account"."carrier_id" = "carriers"."id")
# AND ("account"."groups" @> ARRAY['main_manager']::num_groups[]))
# LEFT JOIN "partners" AS "partner"
# ON ("partner"."id" = "account"."partner_id") Not exactly the same SQL as your subquery approach, which may matter considering you are using a left join. If you really want the subquery, it's best to use a different class: DB.extension :pg_array
Sequel.extension :pg_array_ops
class Carrier < Sequel::Model
one_to_one :account, class: :MainManagerAccount
end
class Partner < Sequel::Model
one_to_one :account, class: :MainManagerAccount
end
class Account < Sequel::Model
many_to_one :carrier
many_to_one :partner
end
class MainManagerAccount < Account
set_dataset dataset.where(Sequel.pg_array_op(:groups).contains(Sequel.pg_array(['main_manager'], :enum_groups)))
end
puts Carrier.association_left_join(account: :partner).sql
# SELECT * FROM "carriers"
# LEFT JOIN (
# SELECT * FROM "accounts"
# WHERE ("groups" @> ARRAY['main_manager']::enum_groups[])
# ) AS "account"
# ON ("account"."carrier_id" = "carriers"."id")
# LEFT JOIN "partners" AS "partner"
# ON ("partner"."id" = "account"."partner_id") |
Beta Was this translation helpful? Give feedback.
-
One more question. Here the query in DB.extension :pg_array
Sequel.extension :pg_array_ops
GRAPH_BLOCK = proc do |j, lj, js|
Sequel.pg_array_op(Sequel[j][:groups]).contains(Sequel.pg_array(['main_manager'], :enum_groups))
end
class Carrier < Sequel::Model
one_to_one :account, class: :Account, graph_block: GRAPH_BLOCK do |ds|
ds.with_group('main_manager')
end
end |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello. I have three models
But
Carrier.association_left_join(account: :partner)
give meWhy here is not involving
with_group('main_manager')
from association dataset definition?Beta Was this translation helpful? Give feedback.
All reactions