It didnt work...
here is my model (simplified):
Person hasmany books
book belongs to type
while viewing a person, I would like to list all books with each type.
I use afterFind() for setting "virtual fields"... Here is the code
MODEL ->
class Person extends AppModel {
var $name = 'Person';
var $displayField = 'full_name';
var hasMany = 'Book';
function afterFind($result) {
debug('afterFind Person');
foreach($results as $key=>$value) {
$results[$key]['Person']['full_name'] =
$value['Person']['last_name'] . ', ' .
$value['Person']['first_name'];
}
return $results;
}
}
class Book extends AppModel {
var $name = 'Book';
var $displayField = 'title_author';
var belongsTo = 'Type, Person';
function afterFind($result) {
debug('afterFind Book');
foreach($results as $key=>$value) {
$results[$key]['Book']['title_author'] =
$value['Book']['ltitle'] . ' by ' .
$value['Book']['author'];
}
return $results;
}
}
class Type extends AppModel {
var $name = 'Type';
var $displayField = 'name_package';
var hasMany = 'Book';
function afterFind($result) {
debug('afterFind Type');
foreach($results as $key=>$value) {
$results[$key]['Book']['name_package'] =
$value['Book']['name'] . ' [of ' .
$value['Book']['package'] . ']';
}
return $results;
}
}
Of course this is kind of funny, but I tried to use a simple model to
explain...
the debug print is:
afterFind Book
afterFind Person
the afterFind Type never prints, it should be printed first...
If I debug $Person is shows al the required data... Im using recursive
= 2...
this is the controller code (only the view function):
function view($id) {
$this->Person->recursive = 2;
$this->set('person', $this->Person->findById($id));
}
May be is something about the "belongsTo" relation... either if i use
findById or read I get the same result...
Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---