Yii Framework Forum: Activerecord Enhancement - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Activerecord Enhancement

#1 User is offline   egorpromo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 02-December 12

Posted 20 September 2013 - 07:24 AM

In general working of any AR-class which extends CActiveRecord looks in this way. During instantiation AR-class calls CactiveRecord::getMetaData() method. CactiveRecordMetaData class is used inside this method and this class makes query request to database to collect some needed information about needed table. It can be the primary keys and information about fields of table. For highload sites it is redundant to make an aditional query to database.
I propose to create way to escape first additional query to database if php-developer knows exactly what properties of the table are used. If developer don't needs first additional query to database he could reload special method of CactiveRecord in his class to return known information about table.

class myAR extends CActiveRecord
{
/* Any needed methods */

	public function getActiveRecordMetaData()
	{
		return array(
			'primary_key'=>'id',
			'fields'=array(
				'username',
				'password',
				'email'
			)
		);
	}
}


I don't know exactly what information CactiveRecordMetaData in Yii1.1.14 consists of and what information is needed for CactiveRecord to makes his job. Thats why in example above my function returns dummy information.
In core CActiveRecord class method getActiveRecordMetaData() must make a query to database to collect information about table.
So in CActiveRecord it is needed to make getActiveRecordMetaData() method which makes all job for getting information about table. In expanding classes developers can recreate this method for escaping redundant query to database if they knows exactly what is in their table.
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,778
  • Joined: 17-January 09
  • Location:Russia

Posted 20 September 2013 - 11:24 AM

It can be cached easily with one line in connection config, "db" component, enableSchemaCache property.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   egorpromo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 02-December 12

Posted 20 September 2013 - 08:32 PM

As I see in Yii2 it is already done. I am just not working with Yii2 yet and not searching it deeply. As I understand it is mabe by the another table with cached data in database. So there is one additional connection also.
0

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,778
  • Joined: 17-January 09
  • Location:Russia

Posted 21 September 2013 - 04:58 AM

It's done in both 1.1 and 2.0. Backend for storing cache is determined by what you've set in "cache" component. It can be files, database, memcached, apc, zend cache, redis etc.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users