[Dbix-class] Question on expressing relationship to one or other
table depending on ENUM value
John Ramsden
jhnrmsdn at yahoo.co.uk
Wed Mar 25 11:17:47 GMT 2009
[Please excuse resend, but first try was munged in daily digest, possibly d=
ue to RTF characters]
=A0
Hi DBIx::Class hackers
Let's say we have two unrelated tables, "tag" and "asset", each with their =
own sequence of auto-incrementing IDs (so of course the same ID may occur i=
n both, for records unrelated to each other).
Now suppose there is a third table, "edits", set up with a record to allow =
users to log edits to records in either of the above tables. So we define t=
his table by: =
CREATE TABLE `edit_log`
(
`id` int(11) NOT NULL auto_increment,
object_type ENUM('tag', 'asset'),
object_id int(11) NOT NULL,
`comment` text, =
::: =
); =
My question is how does one represent the extra condition on object type to=
define this "one or other" relationship in the DBIx::Class module for the =
edit_log table, and for that matter in the "tag" and "asset" tables? =
Presumably in EditLog.pm it needs to be something along the lines of: =
__PACKAGE__->has_one (asset =3D> 'Ethel::Schema::Asset', { 'self.object_id'=
=3D> 'foreign.id' }, { -is =3D> { 'self.object_type' =3D> 'asset' } );
__PACKAGE__->has_one (tag =3D> 'Ethel::Schema::Tag', { 'self.object_id' =3D=
> 'foreign.id' =
{ -is =3D> { 'self.object_type' =3D> 'tag' } ); =
I'm fairly sure the "-is" syntax is wrong, but that is basically my questio=
n. How should this condition be expressed? =
I did check the documentation, but found no examples of how to express extr=
a conditions. =
Many thanks in anticipation for any replies. =
=A0
Regards
John Ramsden
=
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090325/50c=
76d6d/attachment.htm
More information about the DBIx-Class
mailing list