I already figured it out.I found that getParent(<itemType>)
and getChildren(<itemType>)
return Core_Model_Item_Abstract
. But you must set $_parent_type
and $_children_types[array]
in your child and parent table model respectively (not in _model_dbtable
).
You also must make a getChildrenSelectOfItemType($obj,$params = array()
in your child table model(_Model_DbTable_)
,which returns a Zend_Db_Select
and you have to define what this select will return.
Here ItemType
in SE means moduleName_itemname
(e.g. album_photo ).
Assuming account and bugs having 1:n relation, hence the following has to be in MyModule_Model_DbTable_Bugs.
public function getChildrenSelectOfMyModuleAccount($obj,$params = array())
{
$select = $this->select();
$select ->where('account_id = ?', $obj->getIdentity());
return $select;
}
}
Then you can get the related children by (in your controller)
$account=Engine_Api::_()->getItem('mymodule_account', 1); //1 = matching account_id
.
$bug=$account->getChildren('mymodule_bug'); //return Core_Model_Item_Abstract or row obj
Getting parent table rows is less complicated, declare $_parent_type
in child table and parent_id column must be present in database child table - bugs.
$bug=Engine_Api::_()->getItem('mymodule_bug', 1); //1 = bug_id
$account=$bug->getParent();** //return Core_Model_Item_Abstract/row obj
(don't forget to put a reference column (parent_id) in db bugs table with matching id)
If you set "$_parent_is_owner=true" in MyModule_Model_Bug (without declaring $_owner_type and $_parent_type), the user will become the parent, hence getParent will return the user
One most important thing to know is
Subject, Viewer and Owner
in socialengine context...
Viewer = anyone who is viewing the page(mostly logged in user).e.g. John is a logged-in user who is viewing a photo -a subject.
Subject= Subject is viewed by viewer and/or Viewer actually views the subject. e.g. if user John views an album/photo, album/photo is subject.
Owner=Owner owns an item/subject. e.g. John is owner of his photo(a subject).If John is viewing Jerry's photo, subject is Jerry's photo but owner is Jerry.