[Dbix-class] Adding UNIQUE constraint support

Matt S Trout dbix-class at trout.me.uk
Sun Dec 18 16:50:56 CET 2005


On Sat, Dec 17, 2005 at 05:51:42PM -0500, Daniel Westermann-Clark wrote:
> > Second, I don't think what you're doing is really the same as
> > ->find_or_create() anymore.  I would call it something more like
> > ->update_or_create(), or ->create_or_update(), and leave the
> > original alone as it was.
> 
> You've got a good point.  I set out to make the component a drop-in
> replacement for find_or_create, but it really doesn't do what the
> method name implies.  The method is now named update_or_create.

Top. This feature has been discussed before and I think that was the name
people settled on then.
 
> > It would make more sense for your function to consider the PK as
> > part of the set of UNIQUE keys as well.
> 
> Good idea, I've added this.

I think arguably find, find_or_create, etc. should all default to operating
on the PK but be able to operate on any unique key, maybe with a { key => ... }
attribute. The find methods don't currently take attributes, sadly, which
will be Getting Fixed as I move them over onto the ResultSet object.

> > And the api for defining UNIQUE keys should probably mirror that of
> > PK's as much as possible.
> 
> You can specify multiple UNIQUE constraints currently, each with one
> or more columns.  Are you suggesting the interface be simplified?

Arguably, the primary key should be a special case of the uniques - which
would involve folding this into core, but once we get 0.05 out I'd be
open to that.
 
> > I'd call them "Alternate Keys" or "Secondary Keys" instead, since
> > that's more of a generic relational theory term, whereas UNIQUE is
> > sql-specific.
> 
> Yeah, I went back and forth on the naming for a while, then settled on
> Constraint::Unique.  I figured maybe this would fit better for the
> future, if other constraint types are added.  I could probably still
> be convinced to change the name, though.  :)

I prefer unique constraint as the name - fuzzy memory suggests other things
like LDAP use a similar naing convention, and it certainly seems more
obvious to me what it does this way.

-- 
     Matt S Trout       Offering custom development, consultancy and support
  Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list