Re: has_a and the accessor name

[prev] [thread] [next] [Date index for 2005/03/27]

From: Josef Chladek
Subject: Re: has_a and the accessor name
Date: 19:18 on 27 Mar 2005
Am 26.03.2005 um 09:46 schrieb William Ross:

> On 26 Mar 2005, at 07:38, Josef Chladek wrote:
>
>> maybe this is purely trivial, but i can't find a solution:
>>
>> i have a ont-to-one relationship between two tables:
>>
>> package Newsletter::Main;
>> use base 'Newsletter::DBI';
>>
>> __PACKAGE__->table( "Newsletter" );
>> __PACKAGE__->columns(Primary => qw /id/);
>> __PACKAGE__->columns(Essential => qw /email/ );
>> __PACKAGE__->columns(Others => qw /no_mails modified md5/ );
>> __PACKAGE__->has_a( "id", "Newsletter::Attributes");
>
> from the docs:
>
>     *NOTE* You should not attempt to make your primary key column 
> inflate
>     using has_a() as bad things will happen. If you have two tables 
> which
>     share a primary key, consider using might_have() instead.
>
> Do your tables really need to be separate? If yes, you will need to 
> add a column to one of them that refers to the key in the other, and 
> declare your has_a or might_have on that. You might also want to look 
> at Class::DBI::Relationship::IsA.


out of historic reasons the database is of that structure, applications 
depend on it - so i can't change it.

might_have works perfectly, i use

package AxKit::App::XMLForm::Data::Newsletter::Main;
...
__PACKAGE__->might_have( "myattr" => 
"AxKit::App::XMLForm::Data::Newsletter::Attributes" => qw/vorname 
nachname anrede/);

and

package AxKit::App::XMLForm::Data::Newsletter::Attributes;
...
__PACKAGE__->has_a( "newsletter", 
"AxKit::App::XMLForm::Data::Newsletter::Main");

thanks for that.

one question about is_a:
my application is strong hierarchical, i process my classes topdown, so 
i first create the data in main and THEN set the data in the child 
class(es). it seems that i can't use is_a for that, because is_a wants 
the child to be created first and then creates the parent row(s).

so with is_a there is no way to create Newsletter::Main first and THEN 
the attributes, am i right?
just curious about that, but might_have seems to be a perfect joice...

thanks
josef

has_a and the accessor name
Josef Chladek 07:38 on 26 Mar 2005

Re: has_a and the accessor name
William Ross 08:46 on 26 Mar 2005

Re: has_a and the accessor name
Josef Chladek 19:18 on 27 Mar 2005

Re: has_a and the accessor name
.--- .- -- . ... 18:02 on 26 Mar 2005

Re: has_a and the accessor name
Peter Speltz 06:23 on 28 Mar 2005

Re: has_a and the accessor name
Josef Chladek 07:50 on 28 Mar 2005

Re: has_a and the accessor name
Peter Speltz 17:59 on 28 Mar 2005

Generated at 14:42 on 11 Apr 2005 by mariachi v0.52