-
-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support Through Relationships #1780
base: main
Are you sure you want to change the base?
feat: Support Through Relationships #1780
Conversation
is this a feat or enhancement? 🤔😅 |
This would be a feature 😄 . Will have to review next week. |
39b2366
to
d301173
Compare
@@ -1191,6 +1251,9 @@ defmodule Ash.Actions.Read.Relationships do | |||
has_page? = query.page not in [nil, false] | |||
|
|||
cond do | |||
is_list(relationship.through) -> | |||
false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this will actually be the way that we enable data layers to join through relationships. So this should return true
if the data layer can :lateral_join_through_relationships
or something. For now, nothing will implement this, so we can leave it as a stub and talk about that implementation later. It is actually quite complex to do 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact...yeah returning false
makes sense here, never mind. When its time to support doing this in an optimized way in the data layer, then we'd return true
here.
@@ -612,6 +623,50 @@ defmodule Ash.Actions.Read.Relationships do | |||
) | |||
end | |||
|
|||
defp load_related_records(records, through, cardinality) do | |||
load_statement = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to pass through the actor, tenant, authorize? and tracer options from the parent call to this call.
Additionally, we should call Ash.load
with the list of records, not each individual record. That will be much more optimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I overengineered it. 👷
I'm realizing an issue with our "do it in memory" solution here, which is that limits/offsets in Ash relationships apply "per-related-record". Our in-memory loader here won't be able to provide those same guarantees. I think what we may need to do is make it such that What that would essentially look like in
Then in this loader, we'd do the same thing that lateral joining currently does, but setting the full path to the relationship. What I'm describing is a pretty intense change TBH. I'm happy to support you in the effort, but I imagine it would be quite some time before we can get it where we want it 😓 |
wdym? Could you give an example? I assume if I put limit 1 I should also get 1 related? but yea, I agree, this naive attempt only served to elucidate what really needs to be done. I'm still down to bring this to an end. Step by step, heart to heart. I can at least try. ✊ |
What I mean is that when you do |
Should this PR be closed then?
and
|
Yep! There is also logic in Then we can merge this PR, despite no one being able to use this new relationship option. |
#72
Contributor checklist