我对 Lithiums 的关系有点模糊。我正在尝试使用 Lithium 创建标签云,但我不确定如何在不使用 HABTM 关系的情况下做到这一点。我正在使用 MySQL,顺便说一句。
有什么建议么?
:编辑添加示例代码:
这是我现在正在做的事情的一个非常简化的版本。我有Items
和。Tags
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')
));
?>
如何更改我的代码以便我可以Tags
通过以下方式访问数据$items