[Dbix-class] How to represent this ?

John Napiorkowski jjn1056 at yahoo.com
Thu Jun 28 14:11:07 GMT 2007


--- myshare <mraptor at gmail.com> wrote:

> hi,
> 
> How can I represent the following thing in
> DBIx::Class :
> 
> table rel
> ------------------
> pk_id, table_ref, other_table_id
> 
> and then I can have other tables like this :
> 
> table_blah, table_another_one, table_foo, table_bar
> 
> where table_ref is an integer that tells which table
> I'm relating to i.e. if
> 
> %table_ref = {
>  1 => table_blah,
>  2  => table_another_one,
>  3  => table_foo,
>  4  => table_bar
> }
> 
> So how you will represent this in dbix-class ? I
> preffer the ref-table
> that do the translation to
> be a hash (like I shown here), instead of a table in
> the database ...
> as you may suspect there wouldn't be thousand such
> tables.

Hi,

Since I don't know your business needs my comment may
not be pertinent but is there an important reason you
want the lookup as a Perl hash instead of a table?  I
know sometimes when the list of rows is likely to be
small we tend to feel it's a waste of effort to build
a table and model it, etc. but I've found that it's
really best to let the database handle all the
enforcement of referential rules and types.  I've run
into this time and time again, and everytime I've had
to inherit an application that wasn't properly modeled
relationally it caused trouble.

You could probably do something like the above with a
custom resultset (see the docs for several good
examples of this) that accepted the hash key as a
parameter, if you are really sure this is the best
way.

Good luck!

John


      ____________________________________________________________________________________
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 




More information about the Dbix-class mailing list