Model In Social Engine

In SE there are two kinds of Model

1.DB Model
2.Row Model

Folder stacture

Module
–>Model //all Row model
–>Model/DbTable //all DbTable Model

1. DB Model: This model is used for query in the whole table. In SE the table naming convention is table_name(s). So it is good for us to use plural name for table.

For example. Our table name = engine4_core_rooms[this table is for keeping information of a room in a university]
so, we will use room_id as primary key for SE database table naming convention

So our DB Model will

class ModuleName_Model_DbTable_Rooms extends Engine_Db_Table {

    protected $_rowClass = 'ModuleName_Model_Room'; //This is our Row Model class

}

Note:: Here we must keep in mind that we use Engine_Db_Table calss to extends our new DbTable Class

2.Row Model: This is a very usefull stuff in SE. Every row of a table is itself work as a object here. So we can minimise our join query here if we can use it in a perfact way.

Every DbTable Model has a Row model. A DbTable’s row model is define in DbTabe, as

protected $_rowClass = 'ModuleName_Model_Room';

//This is our Row Model class

That means we have a row model for our Rooms DbTable and which name is Room row model. Here we must keep in mind that we use the same name as we use it in DbTable model. We will
keep it a singular to follow as SE nemin convention.

So our Row model will be

 class ModuleName_Model_Building extends Core_Model_Item_Abstract
 {
	//all function goes there..
 }
 

Note:: We must extends Core_Model_Item_Abstract

Calling convention

DbTable:

 $dbTable = Engine_Api::_()->getDbtable('tablename', 'modeulename');
 $dbTable = Engine_Api::_()->getItemTable('itemname');
 $somereturn = dbTable->someFunction();
 

RowTable

 rowObject = Engine_Api::_()->getItem('itemname', $primaryKey);
 $someReturn = $rowObject->someFunction();
 
Advertisements

Tagged: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: