com>
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
To define a one-to-many relationship, the $_referenceMap is used. As shown in #4, each relationship has
its own sub-array and to ensure maximum flexibility, you inform the class exactly which columns are used in
each table. In our case, the reviews table has a column called places_id which is linked to the id column in the
places table.
NOTE
Both columns entries in the reference map are defined as arrays. This is to allow for composite keys
containing more than one table field.
To actually retrieve the reviews for a given ???place??? record the findDependentRowset() function is used as
shown:
$londonZoo = $places->fetchRow('id = 1');
$reviews = $londonZoo->findDependentRowset('Reviews');
findDependentRowset() takes two parameters: the name of the table class that you wish to receive the data
from and an optional rule name. The rule name must be a key in the _referenceMap previously set up, but if
you don??™t supply one, it will look for a rule with a refTableClass that is the same as the class name of the table
from which the row was created (???Places??? in our case).
Many-to-Many Relationships
By definition, each Place has many reviews which were written by different users.
Pages:
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177