[eluser]mcnux[/eluser]
Ok I'm going to try very hard to make this as clear as possible. I've been reading the Advanced Relationships section over and over and am getting there but I don't get how to get my setup to work.
Essentially what I want is list item's which can optionally have child list items. As this is a one to many self relationship, my table is as follows:
Code:
list_items
==========
id
list_item_id
whatever
I can then set 'list_item_id' FK on 'list_item' to specify that it has a parent list item. Obviously I can then find any child list items by finding 'list_item' where 'list_item_id' is my id.
That's the plan anyhoo. Here's my model:
Code:
class List_item extends DataMapper{
var $has_one = array(
'parent_list_item'=>array(
'class'=>'list_item',
'other_field'=>'list_item',
'join_other_as'=>'list_item',
'join_self_as'=>'list_item'
)
);
var $has_many = array(
'list_item'=>array(
'class'=>'list_item',
'other_field'=>'parent_list_item',
'join_other_as'=>'list_item',
'join_self_as'=>'list_item'
)
);
}
This is obviously wrong as the query executed when I ask for $listItemIDIsOne->list_item->count() is:
Code:
SELECT COUNT(*) AS `numrows`
FROM (`list_items`)
WHERE `id` = 1
AND `list_item_id` IS NOT NULL