How do relationships with composite keys work?
I found this mention of composite keys in the docs:
Ideally I need something like:
A similar effect to have scope_key being a tenant.
7 Replies
There isnβt a way to do that currently, without using manual relationships
Very edge use case. I have some easy alternative options that will work.
While looking for an answer to this same question I ended up here. Hi btw! First message here π I found out the destination_attribute still expects a single atom. Am i correct in assuming there hasn't been any change arround this subject and a manual relationship is still the way to go when one would be trying to write a belongs_to pointing to a table with a composit primary key?
π This forum area is archived, but happy to answer here π You can achieve this kind of thing with the
filter
option
That's correct
Heya, thanks for respondin guys! I thought I'd keep it in one place and kind of missed its an actual archive π
Im not quite sure tho how this would work in my case. As Im trying to set an actual foreign key based of of a primary key thats a composite of 2 fields. Your example just looks like a runtime query instead of being able to save a foreignkey (in postgres) π§ ?
Ah, okay so to have the migration generator do that you can configure the
references
block in the postgres DSL
https://hexdocs.pm/ash_postgres/1.5.15/dsl-ashpostgres-datalayer.html#postgres-references-reference-match_with