Wednesday, September 24, 2008

belongsTo and parent data.

Good Evening,

I'm new to cake, and have reached a dead end with a hasMany, belongTo
problem, and wondered if you guys could help.

This problem has 2 models, Event and EventType.

An Event belongs to an Event Type, for example a soccer match event
would be of the sports event type.

My models are setup as follows:

class Event extends AppModel {
var $name = 'Event';

var $belongsTo = 'Eventtype';

}

class Eventtype extends AppModel {

var $name = 'Eventtype';

var $hasMany = 'Event';
}

The problem occurs when I retrieve an event in my controller. If I
try:

debug($this->Eventtype->find('first'));

This spits out the first event type, and all events of that type...
which is the expected result. However if I try:

debug($this->Event->find('first'));

Then the output is only the details of the first event, and no attempt
to join to the eventtypes table is made in any of the queries.

The documentation (http://book.cakephp.org/view/78/Associations-
Linking-Models-Together
) would have me believe that the belongsTo
relationship should also retrieve the details of the parent.

Can anyone help me out?

Thanks

James

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