competitor.php:
<?php
class Competitor extends AppModel {
var $name = 'Competitor';
var $hasMany = array (
'Competition1'=>array(
'className'=>'Competition',
'foreignKey'=>'competitor_1_id'
),
'Competition2'=>array(
'className'=>'Competition',
'foreignKey'=>'competitor_2_id'
)
);
}
?>
competition.php:
<?php
class Competition extends AppModel {
var $name = 'Competition';
var $belongsTo = array (
'Competitor1'=>array(
'className'=>'Competitor',
'foreignKey'=>'competitor_1_id'
),
'Competitor2'=>array(
'className'=>'Competitor',
'foreignKey'=>'competitor_2_id'
)
);
}
?>
Thanks,
Bryan
On Jun 10, 3:18 pm, audioworld <audiowo...@gmail.com> wrote:
> 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 <audiowo...@gmail.com> 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 <audiowo...@gmail.com> 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 cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment