Consider the situation where each review has to be approved by a
moderator. The new table diagram would look like Figure 5.5.
Figure 5.5: Multiple many-to-many relationship between Places and Users is created via two keys in the Reviews table.
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
In this case, we now have two foreign keys in the Reviews table that link to the Users table. To implement
the second link, a new rule is required in the $_referenceMap for the Reviews table as shown in listing 5.15.
Listing 5.15: Reviews class with updated $_referenceMap
class Reviews extends Zend_Db_Table_Abstract
{
protected $_name = 'reviews';
protected $_referenceMap = array(
'Place' => array(
'columns' => array('place_id'),
'refTableClass' => 'Places',
'refColumns' => array('id')
),
'User' => array(
'columns' => array('user_id'),
'refTableClass' => 'Users',
'refColumns' => array('id')
),
'ApprovedBy' => array( #1
'columns' => array('approved_by'), #2
'refTableClass' => 'Users',
'refColumns' => array('id')
)
);
}
(annotation) <#1 Second rule to link to Users table .>
(annotation) <#2 Field name in reviews table.>
As you can see, we can have multiple rules in the reference map that refer to the same table as long as they
have different names (User and ApprovedBy in this case).
Pages:
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180