Subscribe to DataMgr |
Visit this group |
List Relation Fields allow you to automate the handling of many-to-many relationships using lists. This essentially automates the saveRelationList() method with the added benefit that it brings the list into the recordset returned by getRecords().
You can filter by this value as well, limiting the recordset to records that have at least one of the list items given (so the longer the list you pass in to this key, the more results you are likely to get).
<field ColumnName="Items">
<relation
type="list"
table="items"
field="item_id"
join-table="rec2items"
join-field="rec_id"
/>
</field>
The above example assumes that the join-table has a field of the same name as the primary key field of your main table and that the "join-field" field is the other key field in the join-table and exists in the table indicated in the "table" attribute. If these things are not true, you will need to use a more verbose syntax (introduced in DataMgr 2.1):
<field ColumnName="Items">
<relation
type="list"
table="items"
field="item_id"
join-table="rec2items"
join-table-field-local="rec_id"
join-table-field-remote="item_id"
local-table-join-field="rec_id"
remote-table-join-field="item_id"
/>
</field>
This example indicates the exact same structure as the first example, just using the more verbose format.
If you have a self-referential many-to-many relationship, you can use the "bidirectional" key to indicate if each relationship should be represented in both directions. A self-referential many-to-many relationship is one in which the local (main) table is the same as the remote (related) table and a join-table is in use.
Examine, for example, products that can each have multiple related products. If product A has product B as a related product does that mean that product B should automatically have product A as a related product? If so, set bidirection="true". If not, leave it alone (it defaults to false).