Table names are lower_case_undescored_plural while model names are
FirstCapsSingular, so:
your tables should be:
- persons
--- id <--- using id as primary key makes your life a lot easier
--- name
--- surname
- locations
--- id
--- person_id
--- location_type_id
--- address
--- country
- location_types
--- id
--- description
then your models would be:
class Person {
var $hasMany = array('Location');
}
class Location {
var $belongsTo = array('Person','LocationType');
}
class LocationType {
var $hasMany = array('Location');
}
Now that just makes your models compliant to the conventions and your
life a lot easier. But still LocationType will not show up when fecth
Person data and that is because it is not directly related to the Person
model. The best way to do this is using the Containable behavior
http://book.cakephp.org/view/474/Containable
Ernesto wrote:
> Hello.
>
> i have 3 models
> - Person
> - Location
> - Location_Type
>
> pointing respectively @ 3 tables:
>
> Persons:
> person_id
> name
> surname
>
> Locations:
> location_id
> person_id
> location_type_id
> address
> country
>
> Location_Types:
> location_type_id
> description
>
> the 3 models are linked as follow:
> Person hasMany Location
> Location belongsTo Location_Type
>
> here's the models' code
>
> class person extends AppModel {
> var $hasMany = array(
> "Locations" => array(
> "className" => "Location",
> "foreignKey" => "location_id",
> "dependent" => "true"
> )
> );
> }
>
> class location extends AppModel {
> var $belongsTo = array(
> "Location_Type" => array(
> "className" => "LocationType",
> "foreignKey" => "location_type_id",
> "dependent" => "true"
> )
> );
> }
>
> I can't find out why the "Location_Type"'s data is not showing when i
> load data from the "Person" model
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---