Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.programming
Deviating from "standard" active record concept?
Victor Porton
11/26/2015 7:51:00 PM
I was assigned to write a lightweight ORM in Perl. This includes writing an
active record.
Classic active record pattern implies assignments to fields of a model and
after this a save operation. What about using
model->save({Passport=>123456789, FullName=>"Ivan Grotter"})
(pseudocode)
instead (that it passing all parameters in one hash, instead of assigning
one by one)?
I prefer my variant of active record because it a little simplifies Model
class. What are other advantages and disadvantages of leaving classic active
record and using my method?
--
Victor Porton -
http://porton...
2 Answers
Victor Porton
11/26/2015 8:03:00 PM
0
Victor Porton wrote:
> I was assigned to write a lightweight ORM in Perl. This includes writing
> an active record.
>
> Classic active record pattern implies assignments to fields of a model and
> after this a save operation. What about using
>
> model->save({Passport=>123456789, FullName=>"Ivan Grotter"})
> (pseudocode)
>
> instead (that it passing all parameters in one hash, instead of assigning
> one by one)?
>
> I prefer my variant of active record because it a little simplifies Model
> class. What are other advantages and disadvantages of leaving classic
> active record and using my method?
Hm, now I have realized that save() for a newly created object should assign
its identifier.
It would be inconsistent to assign the identifier but not to assign other
fields. This is an argument toward classic active record (rather than my
variation).
However, alternatively we can make save() to just return the identifier of
the saved object.
--
Victor Porton -
http://porton...
LudovicoVan
11/26/2015 9:26:00 PM
0
On Thursday, November 26, 2015 at 7:51:16 PM UTC, Victor Porton wrote:
> I was assigned to write a lightweight ORM in Perl. This includes writing an
> active record.
>
> Classic active record pattern implies assignments to fields of a model and
> after this a save operation. What about using
>
> model->save({Passport=>123456789, FullName=>"Ivan Grotter"})
> (pseudocode)
>
> instead (that it passing all parameters in one hash, instead of assigning
> one by one)?
You can do that, but it is just a shorthand, i.e. do anyway provide the basic approach.
> I prefer my variant of active record because it a little simplifies Model
> class. What are other advantages and disadvantages of leaving classic active
> record and using my method?
If you are new to this thing, I'd suggest you do read the relevant documentation and start by implementing it "by the book". Indeed, you may think you are simplifying but it may very well bite you later...
Beside the books, here are a couple of (pretty obvious) links:
<
https://en.wikipedia.org/wiki/Active_record_p...
<
https://en.wikipedia.org/wiki/DBIx:...
Good luck,
Julio
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Deviating from "standard" active record concept?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password