Static fields definition in AR

Most ORM have static information about object fields, like in scenario:


class Post extends AR {

 static public function getFieldDefinitions() {

  return array(

   'field1'=>some definition params,

   'field2'=>...

  );

 }

}



those definitions can be created based on database table in proper Command and then modified by developer to fit his needs. It would be much better if AR in Yii also support such template. Benefits would be:

  • reduce database queries for table structure and relations

  • easier handling for situations where AR object should not use all columns from table (i.e. BLOB/CLOB columns witch should be supported in different way, probably in event handlers)

For backward compatibility default implementation of those static functions can fetch information from database schema.

Is there any chance for such modyfication of AR?

Use CDbConnection::schemaCachingDuration

I know about this param, but this doesn’t solve anything in described scenario (fetching BLOBS in Oracle, etc.). Reducing number of queries was only a side effect of this pattern.

Consider situation like this:

I have a table in Oracle:

PAGE {

id numeric,

title varchar(255),

lead BLOB,

body BLOB

}

i can’t remove BLOB columns because there is no other solution in oracle to handle large strings. On the other hand - PDO doesn’t handle well this kind of data when fetching multiple rows (like: SELECT * FROM PAGE) - throws errors.

I would like to easy implement solution like:

  1. I have AR class that handles only "id" and "title" columns (all fetch, insert, update actions only apply to those two columns)

  2. Add getters and setters for BLOB columns which implement lazy loading of this data on demand

  3. Implement afterSave handler which puts data of those columns to database.

I have also tried to implement described pattern on my own (provide static database schema objects), but it is impossible without modyfying CActiveRecord class, because core of current solution resides in "model" function which is static and PHP 5.2 does not implement full overloading of static methods… On the other side custom changes in CActiveRecord is very dirty solution and leads to maintaining custom copy of whole framework…