[Dbix-class] Encapsulate multiple steps for insertion

Richard Jolly Richard.Jolly at bbc.co.uk
Fri Jan 12 18:11:40 GMT 2007


Tobias Kremer wrote:
>> We use what is described as the ActiveRecord approach above, and I'm
>> not that happy with it. It works well enough but the intent of the
>> code is not clear.
> 
> Hmm ... I just decided to go this way, too. It seemed to be
> the most straight- forward solution to me and so far I can't
> think of any trouble this could cause in the long run - the
> intent of the code I just added is quite clear IMHO. Can you
> elaborate on the problems you faced with this approach.

Like the OP, whe have business entities that span mulitple tables and
need to be created within a transaction. That's simple enough, but the
clarity of the code suffers:

  # good - creates a complete record
  $schema->resultset('Foo')->create_bar($data)

  # bad - invalid, partially created business object
  #schema->resultset('Foo')->create($data)

We can't just override create, so that wasn't an option - it needs to be
called as-is within the create_bar transaction, along with a bunch of
other stuff. Get a few cases like that and it's a lot for developers to
remember.

I think we will end up making a domain/business layer on top of DBIC.
But it's a shame, in a way, because DBIC is nearly good enough as is.
We'll want a to continue to be able to write code like this:

  $episode->broadcasts

But should we allow:

  $episode->broadcasts({}, { order_by => 'foo' });

or do we make methods for every common usage:

  $epsiode->broadcasts_by_foo

So if we make a domain layer we have to duplicate all the relationships
already defined in DBIC. You can see this as a good thing, in that we
are constraining the API, giving us a good testing point, etc. But for a
lot of it it seems like making life more difficult for no real benefit.

I'm not knocking the AR approach - it's worked very well for us so far.
But if you've got business logic to implement, how do you make sure it
isn't bypassed without an explicit domain layer?


Richard

> --Tobias
> 
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive:
> http://www.mail-archive.com/dbix-class@lists.rawmode.org/ 


http://www.bbc.co.uk/
This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated.
If you have received it in error, please delete it from your system.
Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.
Please note that the BBC monitors e-mails sent or received.
Further communication will signify your consent to this.
					



More information about the Dbix-class mailing list