[Solar-talk] Solar_Sql_Model to DataMapper/Record/Collection
Ian Szewczyk
roamzero at gmail.com
Sat Jul 21 22:43:52 CDT 2007
Do the offset methods need to be final? I addressed this in an earlier
posting but I think you should optionally be able to access the $_data
in a collection object without going through record objects (in a
manner similar to accessing normally, so if you have related stuff
loaded you wouldn't need to remember to access the existing relation
data with that double underscore, etc). It may be possible to custom
rig something through those offset methods.
On 7/21/07, Rodrigo Moraes <rodrigo.moraes at gmail.com> wrote:
> Hi,
> Following some conversations off-list, I converted Solar_Sql_Model to
> a DataMapper - Record - Collection group of classes. Although they
> need review and refactorings and additions, I've just got everything
> working, from table creation to loading related records and executing
> insert/update/delete's.
>
> There's a lot of things to do, but it's quite advanced. I'd love some
> help with the code, so let me know if you test it and find bugs or see
> improvements. We need to implement some missing parts too. Here are
> the classes:
>
> http://dev.tipos.org/browser/trunk/Tipos/Orm
>
> It's pretty much Solar_Sql_Model after 5 hours in a blender. :) Code
> was moved here and there to achieve what some of us believe is a
> better approach to models. Excuse the names, I've added it to a /Orm
> directory to not mix them with my current models.
>
> * Tipos_Orm_Model - data mapper: stores info about the table, model
> relationships, filters, and executes database operations.
> * Tipos_Orm_Record - represents a single record; extends Solar_Struct;
> I tried to follow the previous Solar record implementation and added
> Solar_Sql_Model new stuff. Each model can implement its own record
> class.
> * Tipos_Orm_Collection - represents a collection of records; extends
> Tipos_Orm_Record. Each model can implement its own collection class.
> * Tipos_Orm_Catalog - Solar_Sql_Model_Catalog with almost no changes.
> * Tipos_Orm_DataFilter - Solar_Sql_Model_Datafilter with no changes
> (the filter part of this model is still missing and wasn't tested).
>
> Below are some code examples (pretty obvious I'm afraid). :)
>
> -- rodrigo
>
> --------------------------------
> Examples
>
> // Fetching a new record (creates the table if not yet created)
> $model = Solar::factory('Tipos_Model_Area');
> $record = $model->fetchNew();
>
> // Saving some data
> $record->name = 'My record name';
> $record->save();
>
> // Updating some data
> $record->name = 'I changed my mind';
> $record->save();
>
> // Deleting the record
> $record->delete();
>
> The model is always available for a record/collection through getModel():
>
> // Get the model and execute a new fetch
> $model = $record->getModel();
> $collection = $model->fecthAll();
>
> // Update collection
> foreach($collection as $another_record) {
> $another_record->status = 1;
> }
> $collection->save();
> _______________________________________________
> Solar-talk mailing list
> Solar-talk at lists.solarphp.com
> http://mailman-mail3.webfaction.com/listinfo/solar-talk
>
--
IAN SZEWCZYK
ian at roamzero.com
roamzero at gmail.com
iaszew01 at louisville.edu
More information about the Solar-talk
mailing list