Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #5986 > unrolled thread

Deviating from "standard" active record concept?

Started byVictor Porton <porton@narod.ru>
First post2015-11-26 21:51 +0200
Last post2015-11-26 13:26 -0800
Articles 3 — 2 participants

Back to article view | Back to comp.programming


Contents

  Deviating from "standard" active record concept? Victor Porton <porton@narod.ru> - 2015-11-26 21:51 +0200
    Re: Deviating from "standard" active record concept? Victor Porton <porton@narod.ru> - 2015-11-26 22:03 +0200
    Re: Deviating from "standard" active record concept? Julio Di Egidio <julio@diegidio.name> - 2015-11-26 13:26 -0800

#5986 — Deviating from "standard" active record concept?

FromVictor Porton <porton@narod.ru>
Date2015-11-26 21:51 +0200
SubjectDeviating from "standard" active record concept?
Message-ID<n37nrd$koj$1@speranza.aioe.org>
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://portonvictor.org

[toc] | [next] | [standalone]


#5987

FromVictor Porton <porton@narod.ru>
Date2015-11-26 22:03 +0200
Message-ID<n37oho$nhq$1@speranza.aioe.org>
In reply to#5986
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://portonvictor.org

[toc] | [prev] | [next] | [standalone]


#5988

FromJulio Di Egidio <julio@diegidio.name>
Date2015-11-26 13:26 -0800
Message-ID<97034ede-f4a0-477a-b1cd-619581b2038a@googlegroups.com>
In reply to#5986
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_pattern>
<https://en.wikipedia.org/wiki/DBIx::Class>

Good luck,

Julio

[toc] | [prev] | [standalone]


Back to top | Article view | comp.programming


csiph-web