Many-to-one embedded resource is array when using in view #3618
-
I am using PostgREST via supabase-js & postgrest-js. My main table Client code const { data, error } = await supabase
.from('batches_flat')
.select('*, collections(*), batch_category(*)')) Problem
batch_category: { /* */ },
collections: [ { /* */ } ], I reduced the problem to this view: create or replace view foo as
select
b.id as batch_id,
b.collection_id as ref_collection_id, -- fix
collections.id as collection_id
from batches b
left join collections on b.collection_id = collections.id; Without the line marked as "fix", I'd get select
-- ...
-- collections.id as collection_id, -- works, but provides array for many-to-one
b.collection_id, -- fails This will fail with "Could not embed because more than one relationship was found for 'batches_flat' and 'collections'". |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I'm a bit confused with your first example. Did you mean to put .select('*, locations(*), batch_category(*)'))
Ah, maybe there's another FK column selected in the view that has a const { data, error } = await supabase
.from('batches_flat')
.select('*, collections!ref_collection_id(*), batch_category(*)')) The error shows the possible relationships in the |
Beta Was this translation helpful? Give feedback.
I'm a bit confused with your first example. Did you mean to put
collections
instead oflocations
here?Ah, maybe there's another FK column selected in the view that has a
to-many
relationship with thecollections
table. What's the full error here? In thehint
there should be a message that says "Try changing 'collections' to one of the following...". If the fix you mention is like this in your viewb.collection_id as ref_collection_id
, then this should get the relationship that you want: