QQ and Association Tables (Many-to-Many Relationships)
One key feature of
Qcodo Query is its ability to treat relationships in Association tables just like
any other foreign key relationship.
QQ has the ability to perform the full set of
QQ functionality
(including conditions, expansions, ordering, grouping, etc.) on tables related via association tables
just as it would on tables related via a direct foreign key.
Naming standards for the many to many relationship are the same as the naming standards for the public methods
for associating/unassociating in the class, itself. So just as
$objPerson->GetProjectAsTeamMemberArray will
retrieve an array of Project objects that are associated to this Person object as a "Team Member",
QQN::Person()->ProjectAsTeamMember will refer to the "team_member_project_assn" association table joined against
the "person" table.
And again, because all the
QQ Nodes are linked together, you can go from there to pull the project table, itself, as
well as any columns from that project table. In fact, the linkages can go indefinitely.
QQN::Person()->ProjectAsTeamMember->Project->ManagerPerson->FirstName refers to the "first name of the manager
of any project that this person is a team member of."
More importantly, when performing
Qcodo Queries across association tables, we can
Expand on the many-to-many
relationship, which would use a special virtual attribute to help describe the individual object, itself, which was involved for the join.
In this case, if we were to do a query of the person table, expanding on any ProjectAsTeamMember objects, the actual project that is joined is available
to the Person object as $objPerson->_ProjectAsTeamMember.
And finally, on a similar note, you could instead use
ExpandAsArray which would do a similar expansion
on the associated object, but store it as an array. See below for the differences of each.