hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.16k stars 2.76k forks source link

Support where clause when creating relationships ? #2298

Open revskill10 opened 5 years ago

revskill10 commented 5 years ago

In Rails and ActiveRecord, we could have the following relationships:

class Person < ActiveRecord::Base
  has_many :person_businesses
  has_many :employees, through: :employee_businesses, source: :business
  has_many :employee_businesses, -> { where(person_type: 'employee') }, class_name: 'PersonBusiness'
  has_many :customers, through: :customer_businesses, source: :business
  has_many :customer_businesses, -> { where(business_type: 'customer') }, class_name: 'PersonBusiness'
end

As we see, between two tables, there're many kinds of array_relationship could be created, using a where clause.

Is this feature possible with Hasura ?

jorroll commented 5 years ago

I think the docs answer your question indirectly. Read the section on many-to-many relationships. Specifically, I think you could address this using a SQL View: https://docs.hasura.io/1.0/graphql/manual/schema/relationships/database-modelling/many-to-many.html#flattening-a-many-to-many-relationship-query

revskill10 commented 5 years ago

@thefliik If i am not wrong, introducing another view might not be optimal solution, as this could be automatic manipulated by Hasura, just like aggregated fields.

ItsWendell commented 3 years ago

Would love to see some kind of support for this too, as stated on the docs there, modelling many to many relationships through a view will abandon your permissions in your original table, which even Hasura recommends not to do.

Having the ability to define your relationships like described above, or in a similar way, could fix the resolving of a join table, without the need to flatten manually and losing your permissions state on the original table.

NickStefan commented 1 year ago

Have there been any updates on this?