Re: Working on a many-to-many CDBI::Relationship

[prev] [thread] [next] [Date index for 2005/05/14]

From: Matt S Trout
Subject: Re: Working on a many-to-many CDBI::Relationship
Date: 11:19 on 14 May 2005
On Fri, May 13, 2005 at 07:25:40PM -0500, Stepan Riha wrote:
> I'm working on a CDBI::Relationship plugin wich adds an "associated_with" CDBI
> class method for specifying many-to-many relationships. I've got a question on
> the proper way to plug the "many_to_many" method into the CDBI class that uses
> it.  Do I simply do it in the BEGIN block of my plugin class?  This works,
> however my code adds it to the CDBI class but one would probably prefer it be
> added to the class that "uses" it (University::DBI, in my example).

Have a look at the many-to-many stuff I was working on under
http://trout.me.uk/perl/ - it's far from release quality but if you can
steal any ideas from it, please do :)

> ---------------------------------------------------------------------
> ## The application code
> ...
> ## Get a student's classes
> my @classes = $student->classes;
> 
> ## Associate a class with a student
> my $class = University::Class->search(...);
> $student->classes->add_to($class);
> 
> ## Remove a student from a class
> $class->students->remove_from($student);
> ---------------------------------------------------------------------

That's ... icky, I think. Why not just have

$student->add_to_classes($class);

so that it keeps a similar method naming convention to has_many relationships?

        -- 
             Matt S Trout           Website: http://www.shadowcatsystems.co.uk
  Technical Director        E-mail:  mst (at) shadowcatsystems.co.uk
Shadowcat Systems Ltd.

Working on a many-to-many CDBI::Relationship
Stepan Riha 00:25 on 14 May 2005

Re: Working on a many-to-many CDBI::Relationship
Matt S Trout 11:19 on 14 May 2005

Generated at 15:51 on 25 May 2005 by mariachi v0.52