[Solar-talk] The new model class discussion, some questions
Paul M Jones
pmjones at ciaweb.net
Mon Feb 19 06:23:00 PST 2007
On Feb 19, 2007, at 6:01 AM, Rodrigo Moraes wrote:
> I've been playing with Doctrine and some time ago I started my very
> simple orm (thus the lower case ;). Without know I was taking a
> similar approach (very humble observation).
Great Minds Think Alike. :)
> I would call this a model-centric versus record-centric difference;
> Solar focus on a model, while the other examples the focus on the
> record.
Yes, this sounds right; or even, table-centric vs. record-centric.
> Although I don't see what you would not be able to achieve with a
> Solar_Sql_Model_Record subclass, I understand that in Solar the
> model/table comes first and defines the records; others start with a
> record to define the model. This is a key difference for subclassing &
> domain logic.
Yes, that sounds exactly right.
Here's another example (hopefully more clear) as to how
Solar_Sql_Model works:
// get an instance of a Model
$model = Solar::factory('Solar_Model_Nodes_Wikis');
// work with one Record from the Model
$record = $model->fetch(1);
foreach ($record->revisions as $revision) {
$revision->dump();
}
$record->subj = 'Something';
$record->save();
// work with a RecordSet from the model
$recordset = $model->fetchAll(array(
'where' => array('area_id = ?' => 1),
));
foreach ($recordset as $record) {
echo $record->subj;
}
// work with the Model as a whole
$data = array('status' => 'public');
$where = array('area_id = ?' => 1);
$model->update($data, $where);
That last one, "work with the Model as a whole", is a key feature; in
Solar, you should be able to access the Model (i.e., the table and
its relationships) directly if needed.
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>
More information about the solar-talk
mailing list