Mailing List Archive

Using C::DBI::Loader::Relationship with Model::CDBI?
Since I'm not able to automatically setup my table relationships using
Class::DBI::Loader::mysql (I think that requires InnoDB tables), I was
looking to add on the Loader::Relationship module which lets you specify
your relationships using english syntax. In a non-Catalyst app,
I can do something like this:

use Class::DBI::Loader;
use Class::DBI::Loader::Relationship;
my $loader = Class::DBI::Loader->new(
dsn => 'dbi:mysql:test',
namespace => 'MyApp',
);
$loader->relationship( "a user has groups" );

I tried to do something similar in Catalyst, but I can't figure out how
to make the Relationship class load up properly:

package MyApp::Model::CDBI;
use base 'Catalyst::Model::CDBI';

__PACKAGE__->config(
dsn => 'dbi:mysql:test',
additional_classes => [qw/Class::DBI::Loader::Relationship/],
);
__PACKAGE__->loader->relationship( "a user has groups" );

I've also tried __PACKAGE__->relationship( ... ) and use'ing the
Relationship module at the top of the module.

Thanks,
-Andy
Using C::DBI::Loader::Relationship with Model::CDBI? [ In reply to ]
Am 05.04.2005 um 22:55 schrieb Andy Grundman:

> Since I'm not able to automatically setup my table relationships using
> Class::DBI::Loader::mysql (I think that requires InnoDB tables), I was
> looking to add on the Loader::Relationship module which lets you
> specify
> your relationships using english syntax. In a non-Catalyst app,
> I can do something like this:
>
> use Class::DBI::Loader;
> use Class::DBI::Loader::Relationship;
> my $loader = Class::DBI::Loader->new(
> dsn => 'dbi:mysql:test',
> namespace => 'MyApp',
> );
> $loader->relationship( "a user has groups" );
>
> I tried to do something similar in Catalyst, but I can't figure out how
> to make the Relationship class load up properly:
>
> package MyApp::Model::CDBI;
> use base 'Catalyst::Model::CDBI';
>
> __PACKAGE__->config(
> dsn => 'dbi:mysql:test',
> additional_classes => [qw/Class::DBI::Loader::Relationship/],
> );
> __PACKAGE__->loader->relationship( "a user has groups" );
>
> I've also tried __PACKAGE__->relationship( ... ) and use'ing the
> Relationship module at the top of the module.
>
> Thanks,
> -Andy

try

use NEXT;

sub new {
my $class = shift;
my $self = $class->NEXT::new(@_);
$self->loader->relationship(...);
return $self;
}

--
sebastian
Using C::DBI::Loader::Relationship with Model::CDBI? [ In reply to ]
You may need to overload the constructor ..

use Class::DBI::Loader::Relationship;

sub new {
my ($self, $c) = @_;
$self = $self->NEXT::new($c);

$self->loader->relationship( "a user has groups" );

return $self;
}

On 4/5/05 12:55 PM, "Andy Grundman" <andy@hybridized.org> wrote:

> Since I'm not able to automatically setup my table relationships using
> Class::DBI::Loader::mysql (I think that requires InnoDB tables), I was
> looking to add on the Loader::Relationship module which lets you specify
> your relationships using english syntax. In a non-Catalyst app,
> I can do something like this:
>
> use Class::DBI::Loader;
> use Class::DBI::Loader::Relationship;
> my $loader = Class::DBI::Loader->new(
> dsn => 'dbi:mysql:test',
> namespace => 'MyApp',
> );
> $loader->relationship( "a user has groups" );
>
> I tried to do something similar in Catalyst, but I can't figure out how
> to make the Relationship class load up properly:
>
> package MyApp::Model::CDBI;
> use base 'Catalyst::Model::CDBI';
>
> __PACKAGE__->config(
> dsn => 'dbi:mysql:test',
> additional_classes => [qw/Class::DBI::Loader::Relationship/],
> );
> __PACKAGE__->loader->relationship( "a user has groups" );
>
> I've also tried __PACKAGE__->relationship( ... ) and use'ing the
> Relationship module at the top of the module.
>
> Thanks,
> -Andy
>
>
>
>
> _______________________________________________
> Catalyst mailing list
> Catalyst@lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>

--
michael reece :: web engineer :: mreece@sacbee.com :: (916)321-1249
Using C::DBI::Loader::Relationship with Model::CDBI? [ In reply to ]
Sebastian Riedel wrote:
> try
>
> use NEXT;
>
> sub new {
> my $class = shift;
> my $self = $class->NEXT::new(@_);
> $self->loader->relationship(...);
> return $self;
> }

Nice, this works! But I don't really understand why it does. The
Relationship class just adds a relationship() method to
Class::DBI::Loader::Generic's namespace. I guess the object getting set
in loader() was created before Relationship was added, or something like
that?

FYI I didn't need 'use NEXT;' for whatever reason.

--
Andy Grundman
Using C::DBI::Loader::Relationship with Model::CDBI? [ In reply to ]
Am 06.04.2005 um 00:00 schrieb Andy Grundman:

> Sebastian Riedel wrote:
>> try
>> use NEXT;
>> sub new {
>> my $class = shift;
>> my $self = $class->NEXT::new(@_);
>> $self->loader->relationship(...);
>> return $self;
>> }
>
> Nice, this works! But I don't really understand why it does. The
> Relationship class just adds a relationship() method to
> Class::DBI::Loader::Generic's namespace. I guess the object getting
> set in loader() was created before Relationship was added, or
> something like that?

The magic line is "my $self = $class->NEXT::new(@_);", because
loader gets initialized in the new method of our SUPER class...

> FYI I didn't need 'use NEXT;' for whatever reason.

Right, it's already used in Catalyst::Base...

--
sebastian