Self reference: retrieve by association

0
Can someone explain to me why, when performing a retrieve by association on a self-reference, it will give me the parent of my object, but doing a retrieve by database on the same object will give me the children? I thought that the rule was that, when performing a by association retrieve, if there are no objects in memory it will turn into a database retrieve. So why would it then suddenly retrieve the parent instead of its children?
asked
1 answers
1

Hey Kurt,

Self associations operate a little different than standard associations. To what extent I'm not sure, but it seems like you ran into one of those differences. One thing to keep in mind, if you have a many to one set up, is that retrieval by association happens as if your current object is the child, since the child is the owner of those self associations. This makes sense with the behavior you're seeing.

In the case of the retrieval over association from the database, it's possible the system/platform is interpreting this retrieval in the opposite direction, treating your current object as a parent, which kind of makes sense because you're drilling down into associated objects when retrieving over the database.

 

Hope this helps. You can find more documentation including a helpful video here: https://docs.mendix.com/refguide/query-over/

 

Happy coding!

answered