I have two schemas Cred and Flag in public schema. Both are not directly connected. There is CredFlag in private schema which I believe can be connected through tenant with Cred. Also CredFlag belongs to Flag in public schema.
I need to write a query to get all flags of a cred.
Not sure how to join the above query with Flag. How to write query for this case that deals with public and private schema? Also is my query above right?
You cannot write it like that, as AFAIK schema name cannot be dynamic. What you need to do is:
prefix = Repo.one!(from c in Cred, where: c.id == ^tennant_id, select: c.tennant)
cred_flags = put_query_prefix(CredFlag, prefix)
from cred_flag in cred_flags,
inner_join: flag in Flag,
on: cred_flag.flag_id == flag.id
Alternatively (additionally) you can set @schema_prefix in Flag to make it a little bit easier.