On Oct 9, 2006, at 3:35 PM, Emils wrote:

>
> My experience with CakePHP has only begun but after creating some  
> small
> examples with great help of the cake manual I think some areas of
> interest suffers.
>
> A very common issue (problem for starters) is when you have a
> one-to-many relation in the data source. For an example we can use a
> list. A list has an id, a name and an owner. Every list has many items
> (one to many). Therefore I'm creating another table called listrows.
> The new table will have a id, a listId (to it's parent in the first
> table) and a name.
>
> List:
> id,name,owner
>
> Listrows:
> id,listId,name
>
> The relation is id->listId.
>
> How do I use cake for the best implementation of this? If I create a
> Controller/Model/View called List(s), my ListController will have
> problems after fetching $this->List->fetchAll(); to get the listId's
> which belongs to the current list.

Try this:

lists:
id, name, owner

list_rows:
id, list_id, name

/app/models/list.php:

class List extends AppModel
{
        var $name = 'List';
        var $hasMany = array('ListRow' => array('className'=>'ListRow'));
}

/app/models/list_row.php:

class ListRow extends AppModel
{
        var $name = 'ListRow';
        var $belongsTo = array('List' => array('className'=>'List'));
}

====

If in a controller,  you do $this->List->findAll() or $this->ListRow- 
 >findAll(), you should get the right data, associated with its  
counterpart.

-- John

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

Reply via email to