Don't you mean that each Immobilie hasMany Anhänge,
and every Anhang belongsTo an Immobilie?
I.e. your Anhänge model is correct, but the Immobilie model is wrong.

On 19 Oct 2008, at 03:35, havanna wrote:

>
> Hi together,
> I started with cakePHP and I'm a bit confussed about the relations
> hasMany and belongsTo.
>
> Because it's a old application which I want to change onto MVC with
> Cake, the table names are given.
>
> I have a table named "immobilien" (real esteat) and anhaenge
> (attachements). I can have n anhaenge for one entry in immobilie. The
> primary key in both is (also historical) objektnummer.
>
> In the model immobilien I tried this:
>    var $hasMany = array('Immobilien' => array(
>      'className' => 'Immobilien',
>      'foreignKey' => 'objektnummer')
>    );
>
> In the model anhaenge I tried this:
>    var $belongsTo = array(
>      'Immobilien'=>array(
>          'className' => 'Immobilien',
>          'foreignKey' => 'objektnummer'
>      )
>    );
> In both models I give the parameter for $useTable and $primaryKey.
>
> If I call find all from the controller Immobilien I got a error that
> show me that the relationship between the table immobilien and
> anhaenge wasn't build by Cake.
> If I use $hasOne in both models instead, every things works fine.
>
> If I try to use a custom query in immobilien model like this:
>
>    var $hasMany = array(
>    'Anhaenge' => array('className' => 'Anhaenge',
>                        'foreignKey' => 'objektnummer',
>                        'finderQuery' => "SELECT
> `Immobilien`.`objektnummer`,
>                                         `Immobilien`.`anbieternr`,
>                                         `Immobilien`.`plz`,
>                                         `Immobilien`.`ort`,
>                                         `Immobilien`.`gesamtpreis`,
>                                         `Immobilien`.`iso_waehrung`,
>                                         `Anhaenge`.`objektnummer`,
>                                         `Anhaenge`.`pfad`,
>                                         `Anhaenge`.`anhangtitel`,
>                                          FROM `immobilien` AS
> `Immobilien`
>                                          LEFT JOIN `anhaenge` AS
> `Anhaenge`
>                                         ON
> (`Immobilien`.`objektnummer` = `Anhaenge`.`objektnummer`)",
>                        'counterQuery' => ''
>    )
>  );
>
> I got the same error as using $hasMany in the easy way - Cake always
> ignore my $hasMany.
>
> Is this normal?
>
> I'm using Cake 1.2.0.7692 RC3
>
> Regards Thomas
>
> >


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to