I'm a little foggy with Lithiums relationships. I'm trying to create a tag cloud using Lithium but I'm not sure how to do this without using HABTM relationships. I'm using MySQL, btw.
Any suggestions?
:edited to add sample code:
Here is a very simplified version of something I'm working on right now.
I have Items
, Tags
and ItemsTags
.
<?php
namespace app\models;
class Tags extends \app\extensions\data\Model {
public $hasMany = array('ItemsTags');
// {{{ schema
protected $_schema = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'title' => array('type' => 'string'),
'created' => array('type' => 'integer'),
'modified' => array('type' => 'integer')
);
// }}}
}
?>
<?php
namespace app\models;
class Items extends \app\extensions\data\Model {
public $hasMany = array('ItemsTags');
// {{{ schema
protected $_schema = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'title' => array('type' => 'string'),
'sku' => array('type' => 'string'),
'price' => array('type' => 'float'),
'created' => array('type' => 'integer'),
'modified' => array('type' => 'integer')
);
// }}}
}
?>
<?php
namespace app\models;
class ItemsTags extends \app\extensions\data\Model {
public $belongsTo = array('Tags', 'Items');
// {{{ schema
protected $_schema = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'tag_id' => array('type' => 'integer'),
'item_id' => array('type' => 'integer'),
'created' => array('type' => 'integer'),
'modified' => array('type' => 'integer')
);
// }}}
}
?>
<?php
$items = Items::find('first', array(
'conditions' => array('myField' => 'myCondition')
));
?>
How can I change my code so that I can access Tags
data via $items