Recursive Model association

2008-09-28 Thread [EMAIL PROTECTED]

Hey Bakers,

what is wrong in this association ? I can't get the recursive Relation
running.
I need the location name for routing the image.

It should be stored in. But is doesn'exists.
$data[Picture][Gallery][Location][location_name]

Here is the code:

 array('className' =>
'Location','foreignKey' => 'location_id'));
var $hasMany = array('Pictures' => array('className' =>
'Picture','foreignKey' => 'gallery_id','dependent' => false));
}

class Location extends AppModel {
var $name = 'Location';
var $hasMany = array('Gallery' => array('className' =>
'Gallery','foreignKey' => 'location_id','dependent' => false));
}

class Picture extends AppModel {
var $name = 'Picture';
var $belongsTo = array(
'Gallery' => array('className' => 
'Gallery','foreignKey' =>
'gallery_id'),
'User' => array('className' => 'User','foreignKey' => 
'user_id')
);
}

#Controller Action:
$this->Picture->findbyid($id);

?>

Regards
Markus
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Recursive model

2007-02-26 Thread Felix Geisendörfer
>
> Thanks, that worked. One small addition is that I had to add className
> in the association array as well, otherwise Cake would complain about
> non-existent classes ParentStudy and ChildStudy.
Yeah I was about to add that but since you were already using assoc 
params and I couldn't remember the exact API I assumed you'd figure it 
out ^^.

-- Felix
--
http://www.thinkingphp.org
http://www.fg-webdesign.de


Martin Schapendonk wrote:
> 2007/2/26, Felix Geisendörfer <[EMAIL PROTECTED]>:
>   
>> Try naming the hasMany study 'ChildStudy' and the belongsTo 'ParentStudy'.
>> That should work.
>> 
>
> Thanks, that worked. One small addition is that I had to add className
> in the association array as well, otherwise Cake would complain about
> non-existent classes ParentStudy and ChildStudy.
>
> Regards,
>
> Martin
>
>   

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Recursive model

2007-02-26 Thread Martin Schapendonk
2007/2/26, Felix Geisendörfer <[EMAIL PROTECTED]>:
> Try naming the hasMany study 'ChildStudy' and the belongsTo 'ParentStudy'.
> That should work.

Thanks, that worked. One small addition is that I had to add className
in the association array as well, otherwise Cake would complain about
non-existent classes ParentStudy and ChildStudy.

Regards,

Martin

-- 
  Martin Schapendonk, [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Recursive model

2007-02-26 Thread Felix Geisendörfer
Try naming the hasMany study 'ChildStudy' and the belongsTo 
'ParentStudy'. That should work.

-- Felix
--
http://www.thinkingphp.org
http://www.fg-webdesign.de


Martin Schapendonk wrote:
> Hi there,
>
> Using CakePHP 1.2 (r4451).
>
> I have a model "Study" that references itself (three attributes: id,
> parent_id, name). The Model is defined as follows (extra stuff removed
> for simplicity):
>
>  class Study extends AppModel {
>   var $name = 'Study';
>   var $hasMany = array(
> 'Study' => array(
>   'associationForeignKey' => 'parent_id'
> )
>   );
>   var $belongsTo = array(
> 'Study' => array(
>   'foreignKey' => 'parent_id'
> )
>   );
> }
> ?>
>
> I use a scaffolding controller to get up and running quickly. The
> controller doesn't show me any Studies, and the debug log tells me:
>
> SELECT `Study`.`id`, `Study`.`parent_id`, `Study`.`naam`,
> `Study`.`id`, `Study`.`parent_id`, `Study`.`naam` FROM `studies` AS
> `Study` LEFT JOIN `studies` AS `Study` ON `Study`.`parent_id` =
> `Study`.`id` WHERE (1 = 1) LIMIT 20
>
> Error: 1066: Not unique table/alias: 'Study'
>
> Which seems rather logical, since the SQL query contains the alias
> 'Study' twice.
>
> Am I doing something wrong, or should I report a ticket?
>
> Regards,
>
> Martin
>
>   

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Recursive model

2007-02-26 Thread Martin Schapendonk

Hi there,

Using CakePHP 1.2 (r4451).

I have a model "Study" that references itself (three attributes: id,
parent_id, name). The Model is defined as follows (extra stuff removed
for simplicity):

 array(
  'associationForeignKey' => 'parent_id'
)
  );
  var $belongsTo = array(
'Study' => array(
  'foreignKey' => 'parent_id'
)
  );
}
?>

I use a scaffolding controller to get up and running quickly. The
controller doesn't show me any Studies, and the debug log tells me:

SELECT `Study`.`id`, `Study`.`parent_id`, `Study`.`naam`,
`Study`.`id`, `Study`.`parent_id`, `Study`.`naam` FROM `studies` AS
`Study` LEFT JOIN `studies` AS `Study` ON `Study`.`parent_id` =
`Study`.`id` WHERE (1 = 1) LIMIT 20

Error: 1066: Not unique table/alias: 'Study'

Which seems rather logical, since the SQL query contains the alias
'Study' twice.

Am I doing something wrong, or should I report a ticket?

Regards,

Martin

-- 
  Martin Schapendonk, [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---