NAME

SPOPS::Configure::DBI - Define additional configuration methods

SYNOPSIS

my $init_classes = SPOPS::Configure::DBI->parse_config( { config => $CONFIG->{SPOPS} } );

DESCRIPTION

We override the method additional_work() from SPOPS::Configure so we can create subroutines in the classes that want to link_to other objects, among other things.

It is possible -- and perhaps desirable for the sake of clarity -- to create a method within SPOPS::DBI that does all the work for us, then we would only need to create a subroutine that calls that subroutine.

However, creating routines with the values embedded directly in them should be quicker and more efficient. So we will try it this way.

METHODS

create_relationship( $spops_config )

Get the config and plow through the SPOPS classes, seeing if any of them have the links_to key defined. If so, we create three subroutines with the proper info.

The first is named '${links_to}' and simply returns an arrayref of objects that the main object links to. For instance:

Example:

# $links_to = 'group'
# Retrieve all groups that this user is a member of
my $group_list = eval { $user->group };

The second is named '${links_to}_add' and links the object to any number of other objects. The return value is the number of successful links.

The third is named '${links_to}_remove' and removes links from the object to any number of other objects. The return value is the number of successful removals.

Examples:

# $links_to = 'group'
# First retrieve all groups
my $group_list = eval { $user->group };
print "Group list: ", join( ' // ', map { $_->{group_id} } @{ $group_list } );
>> 2 // 3 // 5

# Now add some more, making the user a member of these new groups
my $added = eval { $user->group_add( [ 7, 9, 21, 23 ] ) };
print "Group list: ", join( ' // ', map { $_->{group_id} } @{ $group_list } );
>> 2 // 3 // 5 // 7 // 9 // 21 // 23

# Now remove two of them
my $removed = eval { $user->group_remove( [ 2, 21 ] ) };
print "Group list: ", join( ' // ', map { $_->{group_id} } @{ $group_list } );
>> 3 // 5 // 7 // 9 // 23

CONFIGURATION FIELDS EXPLAINED

links_to (\%)

The 'links_to' field allows you to specify a SPOPS alias and specify which table is used to link the objects:

{
   'SPOPS-tag' => 'table_name',
}

Note that this relationship assumes a link table that joins two separate tables. When you sever a link between two objects, you are only deleting the link rather than deleting an object. See "TO DO" for another proposal.

We are also considering making 'SPOPS-tag' into 'SPOPS-class' to make this more versatile. See SPOPS::Configure for more info.

TO DO

Make 'links_to' more flexible

We need to account for different types of linking; this may require an additional field beyond 'links_to' that has a similar effect but works differently.

For instance, Table-B might have a 'has_a' relationship with Table-A, but Table-A might have a 'links_to' relationship with Table-B. (Themes in OpenInteract work like this.) We need to be able to specify that when Table-A severs its relationship with one or more objects from Table-B, the actual object is removed rather than just a link between them.

BUGS

COPYRIGHT

Copyright (c) 2000 intes.net, inc.. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHORS

Chris Winters <chris@cwinters.com>