[Dbix-class] Relationship question/database structure

Rolf Schaufelberger rs at plusw.de
Mon Jan 10 19:45:46 GMT 2011


Am 10.01.2011 um 17:59 schrieb Steve:

> Hi All,
> 
> I'm trying to use an existing schema wherein I have a generic table called 'Note' containing - you guessed it, notes!.  The thing is that these notes may be associated with many other types of data and therefore tables in my database.  They may be related to a request, user, device, etc.  I am sure that this is a fairly common use case, but don't see much in the docs or on the list.
> 
> The question is two-fold: What's the best structure, and how do we go about defining the DBIC rels?
> Thanks,
> Steve
> 


I'm using something similar to log status changes. 
I have many tables  with a column "akt_status" of type varchar
and a table allstatus with columns 
 status, timestamp, obj_id, obj_name, 
where obj_name is the name of the table and obj_id the row in that table
and wherein I can log my whole status change history (done with triggers).
(Of course  I cannot define  a foreign key constraint in allstatus!)

So for instance from my table pay_order I define 

__PACKAGE__->has_many ( status  => 'MySchema::DB::Allstatus',  'obj_id', { where => { obj_name => 'pay_order'} });

Thats it, just add the  table info in the attr part of has_many.
 I never need  a relation the other way , from allstatus to one of the status logging tables, 
there is no use case for that.

 
Regards
Rolf Schaufelberger








More information about the DBIx-Class mailing list