[CDBI] A many to many relationship question (getting error)

Giannis Economou <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.class-dbi
Message-ID <[email protected]>
Hello all,

It's the first time I'm trying to setup a many-to-many relationship
between my classes, but it is not working.
Please, can you provide some help?

The tables:
CREATE TABLE users_info (
  uid int primary key,
  uname varchar
)

CREATE TABLE groups (
  gid int primary key,
  group_name varchar
)

CREATE TABLE users_groups (
  uid int,
  gid int,
  PRIMARY KEY  (uid,gid)
)


The packages:

package UsersInfo;
#...
__PACKAGE__->table('users_info');
__PACKAGE__->columns( Primary   => qw/uid/ );
__PACKAGE__->columns( Essential => qw/uname/ );
__PACKAGE__->has_many(groups => [ 'UsersGroups' => 'gid' ]);



package Groups;
#...
__PACKAGE__->table('groups');
__PACKAGE__->columns( Primary   => qw/gid/ );
__PACKAGE__->columns( Essential => qw/group_name/ );
__PACKAGE__->has_many( users => [ 'UsersGroups' => 'uid' ] );



package UsersGroups;
#....
__PACKAGE__->table('users_groups');
__PACKAGE__->columns( Primary   => qw/uid/ );
__PACKAGE__->columns( Essential => qw/gid/ );
__PACKAGE__->has_a( uid => 'UsersInfo' );
__PACKAGE__->has_a( gid => 'Groups' );


and later on on another class:

my $group = new Groups->search( group_name => 'maintainers' )->first;
my $a_user = new UsersInfo->search( uname => $uname )->first;
$a_user->add_to_groups( { gid => $group } );

and I'm getting....

ERROR:
usersinfo is not a column of RemindMe::Data::UsersGroups at
/usr/local/share/perl/5.8.7/Class/DBI/Relationship/HasMany.pm line 112



Thank you...


Regards,
Giannis
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.