I have Items and Units, and want each Item to have one Unit, but that
unit can be used by many.
Items Table
id - int
name - varchar
description varchar
unit_id - int
Units Table
id - int
name - varchar
description - varchar
Items Model
var $hasOne = array( 'Units' = array( 'className' = 'Unit'
You need the relationship both ways:
Item hasOne Unit
Unit belongsTo Item
Add a few items and units into the database. Then go back to the item
controller, edit action and make sure you get a list of all the units:
$this-Item-Unit-find('list'));
Hopefully that helps.
On May 29, 11:53 pm,
Your model relationship should actually be:
Item belongsTo Unit
Unit hasMany Items (optional)
In the Cookbook subsection 3.7.6.3 belongsTo (http://
book.cakephp.org/view/1039/Associations-Linking-Models-
Together#belongsTo-1042, part of 3.7.6 Associations: Linking Models
Together), there is a