How to encode tag cloud in Ltihium without HABTM?
I'm a little hazy with lithium 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 am using MySQL, btw.
Any suggestions?
: edited to add example code:
Here is a very simplified version of what I am currently working on. 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 receive data Tags
via$items
source to share
If you are using SQL, take a look at: How do I perform joins with lithium models? for join examples.
Another way would be to create a "Join" model that uses a custom habtm query. There are some examples of cakePHP that should be adapted with a little noise.
Or, using noSQL with inline docs.
source to share