我已经想通了。我发现getParent(<itemType>) 和getChildren(<itemType>) 返回Core_Model_Item_Abstract。但是您必须分别在子表模型和父表模型中设置$_parent_type 和$_children_types[array](而不是在_model_dbtable 中)。
您还必须在子表model(_Model_DbTable_) 中创建一个getChildrenSelectOfItemType($obj,$params = array(),它返回一个Zend_Db_Select,您必须定义此选择将返回什么。
这里 ItemType 在 SE 中的意思是 moduleName_itemname(例如 album_photo )。
假设帐户和错误具有 1:n 关系,因此 MyModule_Model_DbTable_Bugs 中必须包含以下内容。
public function getChildrenSelectOfMyModuleAccount($obj,$params = array())
{
$select = $this->select();
$select ->where('account_id = ?', $obj->getIdentity());
return $select;
}
}
然后您可以通过(在您的控制器中)获取相关的孩子
$account=Engine_Api::_()->getItem('mymodule_account', 1); //1 = matching account_id
$bug=$account->getChildren('mymodule_bug'); //return Core_Model_Item_Abstract or row obj.
获取父表行不太复杂,在子表中声明$_parent_type,并且数据库子表中必须存在 parent_id 列 - 错误。
$bug=Engine_Api::_()->getItem('mymodule_bug', 1); //1 = bug_id
$account=$bug->getParent();** //return Core_Model_Item_Abstract/row obj(不要忘记在 db bugs 表中添加一个引用列(parent_id)并匹配 id)
如果您在 MyModule_Model_Bug 中设置“$_parent_is_owner=true”(不声明 $_owner_type 和 $_parent_type),用户将成为父母,因此 getParent 将返回用户
最重要的一点是
主题、查看者和所有者
在社交引擎环境中...
查看者 = 正在查看页面的任何人(主要是登录用户)。例如John 是一个登录用户,他正在查看照片 - 一个主题。
主题= 主题被查看者查看和/或查看者实际查看主题。例如如果用户 John 查看相册/照片,则相册/照片是主题。
所有者=所有者拥有项目/主题。例如John 是他的照片(主题)的所有者。如果 John 正在查看 Jerry 的照片,则主题是 Jerry 的照片,但所有者是 Jerry。