another update after some more fiddling around:
make sure to also extend the OTHER direction of the association, the
hasMany.
without this, the "Publisher" model just returned the resources where
it was listed in the "Publisher" field, not the "Co Publisher".

I added the following in the "Publisher" model:

var $hasMany = array ('Resource'=>array
('className'=>'Resource','foreignKey'=>'publisher_id'),'Resource1'=>array
('className'=>'Resource','foreignKey'=>'co_publisher_id'));

and now it shows me ALL the resources where this Publisher is listed,
either as main or co-publisher.

greetings,
karl.

On 10 Jun., 20:55, audioworld <[email protected]> wrote:
> ok, I think I figured it out by reading >50 older postings with the
> keyword "belongsto",
> here is the solution:
>
> I was not aware that the NAME for the association can be just ANYTHING
> without any reference to the database fields or tables. So by just
> using two different names it worked:
>
> var $belongsTo = array ('Publisher1' => array
> ('className'=>'Publisher','foreignKey'=>'publisher_id'),'Publisher2'
> => array
> ('className'=>'Publisher','foreignKey'=>'co_publisher_id').......
>
> thanks to jon bennett from this 
> thread:http://groups.google.com/group/cake-php/browse_thread/thread/7e9e17a5...
>
> cheers,
> karl.
>
> On 10 Jun., 20:20, audioworld <[email protected]> wrote:
>
> > hi and thanks for reading this.
>
> > for a literature database I have a database table "resources" with a
> > field "publisher" and a field "co-publisher". both should point to the
> > same table "publishers" which is a pool of names of persons and
> > companies. they can either be publisher or co-publisher, but should
> > not exist in the "pool" twice.
>
> > so far I was not able to create a valid cake model to have two
> > different fields in the same table point to the id of another table, i
> > tried various syntaxes, e.g.:
>
> > var $belongsTo = array ('Publisher' => array ('foreignKey' => array
> > ('co_publisher_id','publisher_id')).......
>
> > var $belongsTo = array ('Publisher' => 'foreignKey' =>
> > ('co_publisher_id', publisher_id')......
>
> > var $belongsTo = array ('Publisher' => array ('foreignKey' =>
> > 'co_publisher_id'), 'Publisher' => array ('foreignKey' =>
> > 'publisher_id').....
>
> > is this not possible or I am just too stupid to figure it out?
> > thanks and greetings,
> > karl.
--~--~---------~--~----~------------~-------~--~----~
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