3. Querying in Qcodo
* Qcodo Query: Handling Reverse Relationships
<< * Qcodo Query: Handling Association Tables   |   Back to Main   |   Next >>

View Source
will open in a new window
QQ and Reverse Relationships
The power of Qcodo's ORM is the ability not just to code generate the code to handle foreign key relationships, but also the ability to have that code handle the "reverse" foreign key relationships. So in the Examples Site data model, we're talking about not just a Project and its ManagerPerson property... but we're also talking about a Person and methods like GetProjectAsManagerArray().

Qcodo Query also has this built-in capability, which works very similar to the way QQ handles Associations. And this should make sense -- from Person's point of view, it has a "-to-Many" relationship with Project as a Manager (via the reverse relationship), and it has a "-to-Many" relationship with Project as a Team Member (via the association table). Therefore QQ has the ability to perform the full set of QQ functionality (including conditions, expansions, ordering, grouping, etc.) on tables related via these reverse relationships just as it would on tables related via a direct foreign key or association table.

The naming standards for the relationship as well as the differences between Expand vs. ExpandAsArray are all the exact same as the case with association tables.

Get All People, Specifying the Project They Manage (if any), for Projects that have 'ACME' or 'WEB' in it

Notice how some people may be listed twice, if they manage more than one project.

Mike Ho (managing the "State College HR Sxzxxystem" project)
Karen Wolfe (managing the "ACME Website1" project)
Karen Wolfe (managing the "ACME Payments" project)

Same as above, but this time, use ExpandAsArray()

Notice how each person is only listed once... but each person has an internal/virtual _ProjectAsManagerArray which may list more than one project.

Mike Ho
     via: State College HR Sxzxxystem
Karen Wolfe
     via: ACME Website1, ACME Payments