apartmentex icon indicating copy to clipboard operation
apartmentex copied to clipboard

Foreign key issue

Open dima12qw opened this issue 7 years ago • 3 comments

Hi. I have one question. If I create a table that have a foreign key references to tenant's table (fk_id_tenant). How can I create this relation?

dima12qw avatar Jul 25 '17 10:07 dima12qw

If this is a tenant table, you can simply use references(:tablename) The current opts hash for references function in Ecto doesn't seem to support the prefix option (which would allow you to use a foreign key referencing a different schema than the tenant's schema.

See here: https://hexdocs.pm/ecto/Ecto.Migration.html#references/2

Does that answer your question?

Dania02525 avatar Jul 27 '17 15:07 Dania02525

Is there any workaround to create a reference on another schema? Like using execute tu manually create it?

FabienHenon avatar Aug 24 '17 08:08 FabienHenon

@FabienHenon I believe that's against the nature of tenants. Each tenant is their own isolated DB. You can add the foreign key, but I don't believe you'll be able to use a foreign key constraint in PG.

BenMorganIO avatar Oct 06 '18 01:10 BenMorganIO