kurt vansteeland Mon Mar 21 11:59:18 -0400 2011

Subject: Is it possible to have model refer to a view instead of a database table?

I'd like to make a model that references a database view instead of a database table.
So I set the $table_name = 'vw_myview' and in de constructor of my model I set $this->readonly(true);
and then try to read the data with:
$_records = VW_UserWithUserType::find('all', array('conditions'=>array('user_id = ?', $modelid)));

I get the correct count($_records), but all the data in the records is empty.
I iterate over my $_records with:
foreach($_records as $record) { ... bla bla bla ... }

When I do a print_r of my $_record object
VW_UserWithUserType Object ( [errors] => [attributes:ActiveRecord\Model:private] => Array ( [user_id] => 0 [user_name] => [user_firstname] => [user_lastname] => [user_birthdate] => [user_startdate] => [user_enddate] => [user_created_at] => [user_updated_at] => [userusertype_id] => 0 [usertype_id] => 0 [usertype_name] => [date_from] => [date_to] => ) [__dirty:ActiveRecord\Model:private] => [__readonly:ActiveRecord\Model:private] => [__relationships:ActiveRecord\Model:private] => Array ( ) [__new_record:ActiveRecord\Model:private] => 1 )

Is what I'm trying to do not possible with phpactiverecord?
Does anyone have a working sample?

best regards,
Kurt