-
Notifications
You must be signed in to change notification settings - Fork 53
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
getCollectionGraph nested related objects only returning single row #228
Comments
I am using MODX 2.8.1-pl and xPDO 2.8.1-pl |
This isn't a bug. I have done many of these. Of note: I typically do both sides of the relationship (i.e. aggregate with owner foreign) . Also, it does not know WHICH id=5 you are discussing. Look at the format for $xpdo->newQuery. You might need to use 'TestClass.id' => 5 |
@wshawn thanks, I've adjusted my schema to add the aggregate:
And the query like:
But still only get one activity per action fetched. When you say it's not a bug, is this correct behaviour or a limitation of getCollectionGraph()? I was expecting that a EDIT: after more searching it seems this has come up before: #118 with a pr addressing it #123. @opengeek is it likely #123 will be looked at in near future? Thanks |
Your reference is 5 years ago. There are two things you can do to find the criteria break. First, simplify your get collection to the first relation until it is working and subsequently expand it for the next relation and so forth. You can try a simple $TestClass->getMany("actions"). // Aliases are usually capitalized as they are classes and index=index doesn't do anything if I remember correctly. Once you have all of the relations showing up add the criteria. And see if only the ones with TestClass.id=5 is showing. Loop through those and grab one to get its relation. If that all is working then your criteria statement is incorrect. I always had to opt for an external criteria to ensure it was working. Now as to the criteria. There were several instances when I had to use the shorthand form of array for it to work: ['TestClass.id' => 5] instead of array('TestClass.id' => 5). I have no idea why and never wanted to invest more time in discovering the cause. I might also add, that it is typically unnecessary to have a graph that extensive, though I have rarely also had to. An example of a criteria for such a graph:
For a three year old MODX3 example:
In short, I would be looking at your criteria and relations. I also noticed, looking through my code base that I opt to use getObjectGraph much more frequently than getCollectionGraph as I am typically working with a specific object and not a collection of them. Read this firstWow. After rereading your post you are getting what you are asking for. You are asking for a TestClass with an ID of 5. When I suspect you are wanting Activities or Actions. You get a collection of the object class named in the first argument of getCollectionGraph. To get a collection of those you must rewrite the argument to the object you are wanting and build your relation back from there. In essence write the graph backwards as the content you are actually interacting with should be closer to the outside of the graph. In most cases I have found that I don't need the criteria relations only what they point to. You can try
I suspect you will find a single object there with all of your data under it. You also do not need to the getMany as you already have them in the graph. Here is a graph written backwards, as you may see the Client is the current client and as such does not need defined in the criteria. In fact, almost no definitions are needed as it simply relies on the relationships.
I hope this helps. |
I'm trying access nested related objects using getCollectionGraph().
My schema:
Code:
There are multiple related actions and they are all fetched correctly. However with the nested related activities, only one row is returned even though there are multiple rows per action. The row with the highest id is returned only.
getMany() works as expected with multiple activities returned:
Is this a bug anyone else can replicate or am I making a mistake somewhere?
Thanks
The text was updated successfully, but these errors were encountered: