AR will support view if the database give to AR the access to the view like a table. MySQL, PostgreSQL and (from my memories) MsSQL will give you these opportunities.
If you look at this code:
/**
* Returns the metadata for all tables in the database.
* @param string the schema of the tables. Defaults to empty string, meaning the current or default schema.
* @return array the metadata for all tables in the database.
* Each array element is an instance of {@link CDbTableSchema} (or its child class).
* The array keys are table names.
* @since 1.0.2
*/
public function getTables($schema='')
{
$tables=array();
foreach($this->getTableNames($schema) as $name)
$tables[$name]=$this->getTable($name);
return $tables;
}
Uhm … well, now we go for example in the PostgreSQL driver to see the function getTableNames():
"db/schema/pgsql/CPgsqlSchema.php"
/**
* Returns all table names in the database.
* @return array all table names in the database.
* @since 1.0.2
*/
protected function findTableNames($schema='')
{
if($schema==='')
$schema=self::DEFAULT_SCHEMA;
$sql=<<<EOD
SELECT table_name, table_schema FROM information_schema.tables
WHERE table_schema=:schema
EOD;
$command=$this->getDbConnection()->createCommand($sql);
$command->bindParam(':schema',$schema);
$rows=$command->queryAll();
$names=array();
foreach($rows as $row)
{
if($schema===self::DEFAULT_SCHEMA)
$names[]=$row['table_name'];
else
$names[]=$row['schema_name'].'.'.$row['table_name'];
}
return $names;
}
OK, this function performs a query on the database, specifically:
SELECT table_name, table_schema FROM information_schema.tables
WHERE table_schema=:schema
where ":schema" will be replaced with "public", the default schema in PostgreSQL.
Now you can try to create some views and execute the query above, so you will see the views in your resultset.
Views in PostgreSQL does not have write support natively, but there may be associated with the rule that simulate write access by performing a series of commands to the occurrence of events of INSERT, UPDATE, DELETE.
http://www.postgresq…les-update.html
So, in this way you can create a view that can be used to create the model and the crud, use AR to insert/modify/delete a record, doing a query on a single object, but executing all command provided by the rule.
MySQL has a partial support of the view in writing, so i don't know if you can define a workaround like RULE on PostgreSQL:
http://dev.mysql.com…datability.html
For the other DB check the relative documentation, however i think that there is many advantages in using the view if the database allows certain operations.
IMHO using PostgreSQL this is the better solution, because it keeps the application tiny.
Instead in case this is not possible … beh, a more flexible AR that give you the opportunity to get multiple queries from a single save() is the unique solution.
I hope I have written in a comprehensible manner, I don't write very well in English:)