Rob Wilkerson wrote:
> I have a vendors table that contains a field named "address_id" that
> is a foreign key to addresses.id. If I define the models as shown
> below then I'm unable to request a scaffolded version of /vendors/
> without getting an error: "Unknown column 'Address.vendor_id' in 'on
> clause'". I don't want a "vendor_id" in the addresses table because I
> need to share that data with other tables later in the dev cycle (e.g.
> the volunteers table).
>
> class Vendor extends AppModel {
>
> public $name = 'Vendor';
> public $hasOne = array ( 'CommercialVendor', 'Address' );
>
> }
>
> class Address extends AppModel {
>
> public $name = 'Address';
> public $belongsTo = array ( 'Vendor' );
>
> }
>
> If I remove 'Address' from the hasOne array on the Vendor model,
> everything renders, but there's no association between the two. I'm
> new to Cake and I think I'm thinking about this incorrectly, but I
> don't know what I'm missing.
A little time away from it and a re-read of TFM pointed out the error
of my ways. I was defining the relationship intuitively rather than
logically. Intuitively, each vendor has an address, but logically each
address has a vendor:
class Vendor extends AppModel {
public $name = 'Vendor';
public $hasOne = array ( 'CommercialVendor' );
}
class Address extends AppModel {
public $name = 'Address';
public $hasOne = array ( 'Vendor' );
}
This seems to work more like what I'd expect.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---