|
From: Chris W. <ch...@cw...> - 2002-09-24 14:45:48
|
On Tue, 2002-09-24 at 06:55, Eric Veldhuyzen wrote:
> I am a starter with SPOPS and I have a little problem with the links_to
> option.
>
> I have two tables, object and subobject. subobject has two
> foreign keys, so that's two 'has_a' fields. Now I would like to give the
> object table two links_to fields, but I can't figure out how to do
> this.
This is a little complicated for the existing auto-generation scheme.
I'd just go ahead and code it, adding the code in the 'code_class'
configuration option. For example:
'object' => {
class => 'My::object',
isa => [ qw{ My::base } ],
>>>>> code_class => [ 'My::ObjectImpl' ], <<<<<
...
}
Then create the code:
----------------------------------------
package My::ObjectImpl;
use strict;
sub my_subobjects_parent {
my ( $self ) = @_;
return My::subobject->fetch_group({
where => 'object_id_parent = ?',
value => [ $self->id ] })
}
sub my_subobjects_child {
my ( $self ) = @_;
return My::subobject->fetch_group({
where => 'object_id_child = ?',
value => [ $self->id ] })
}
1;
----------------------------------------
Hope this helps.
Chris
--
Chris Winters (ch...@cw...)
Building enterprise-capable snack solutions since 1988.
|