<HTML >
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16788" name=GENERATOR></HEAD>
<BODY >
<DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff
size=2></FONT> </DIV>
<DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2>Hi Oleg, </FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2>Thanks for your advice. I've tried this
and it might be the way to go for me. Id prefer to be able to have a resultset
object for the subclasses as well so that I can do $rs =
$schema->resultset('ClassA')->new(...);</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2></FONT></SPAN></SPAN> </DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2>That way it would ensure that the only the
correct columns were available when creating a new row for
classA.</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2></FONT></SPAN></SPAN> </DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2>I would also be able to search on the
subclass columns - why the need to use frozen columns, why cant you just use
add_columns to add extra cols to the already defined baseclass ones
for the subclass? Maybe this comes down to having just one result_source under
the hood.</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2></FONT></SPAN></SPAN> </DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2>I have managed via a custom resultset
object to use set proxy methods at row creation by intercepting the new_result
method.</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2></FONT></SPAN></SPAN> </DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2>sub new_result
{</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2> my ($self,@args) =
@_;</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2></FONT></SPAN></SPAN> </DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2> #get actual cols for the
table</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2> my @cols =
$self->result_source->columns;</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2></FONT></SPAN></SPAN> </DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2><FONT color=#0000ff> # look for
provided args that are not in table</FONT></FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2><FONT color=#0000ff> # assume they
are proxied args</FONT> </FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2> my
%proxyArgs;</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><FONT size=2><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009> foreach my $k (keys %{$args[0]})
{ <BR>
if (!grep /$k/, @cols)
{ <BR>
$proxyArgs{$k} = delete
$args[0]{$k};<BR></SPAN></SPAN><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009> }</SPAN></SPAN></FONT></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2> }</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2> # create new
row</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2> my $row =
$self->next::method(@args);</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2></FONT></SPAN></SPAN> </DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2> # set proxied
args</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2> foreach my $k (keys %proxyArgs)
{</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2>
$row->$k($proxyArgs{$k});</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2> }</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2>}</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2></FONT></SPAN></SPAN> </DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2></FONT></SPAN></SPAN> </DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2>with this in place, I can now
do:</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2></FONT></SPAN></SPAN> </DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT
size=2>$schema->resultset('SubClass')->create( subClassCol1=> 'xxx',
subClassCol2=>'yyy', baseClassCol=> 'zzz');</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2></FONT></SPAN></SPAN> </DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2>The subClassCol1 and subClassCol2 live in
the sub class's table and the baseClassCol lives in the base class's
Table.</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2>By this method I also ensure that a
base class row exists for every sub class.</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2></FONT></SPAN></SPAN> </DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT size=2>I need to experiment more, but this should
allow me to have Subclass and baseclass resultsets, both searchable on all
columns. Just need to ensure I can get the relationships correct to my other
objects.</FONT></SPAN></SPAN></DIV>
<DIV style="COLOR: black; FONT-FAMILY: arial"><SPAN
style="FONT-WEIGHT: normal; FONT-SIZE: 7.5pt"><SPAN
class=418402109-22012009><FONT
size=2></FONT></SPAN></SPAN> </DIV></DIV><BR>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Oleg Pronin [mailto:syber.rus@gmail.com]
<BR><B>Sent:</B> 22 January 2009 01:40<BR><B>To:</B> DBIx::Class user and
developer list<BR><B>Subject:</B> Re: [Dbix-class] RE: Inheritance
question..<BR></FONT><BR></DIV>
<DIV></DIV>1) DBIx::Class::DynamicSubclass will automaticaly subclass your row
object when<BR> a) fetched from
DB<BR> b) created (->new or
->create)<BR> c) changed subclassing column
<BR> For example when type =
null row is BaseClass, when type = 1 row is ClassA, when 2 row is
ClassB.<BR> my $row =
$rs->new({type => 1}); # $row is
ClassA<BR> $row->type(2);
#$row is ClassB<BR>
$row->type(undef); #$row is BaseClass<BR><BR>2) You can set up dynamic
columns with subclassing if you use DBIx::Class::DynamicSubclass +
DBIx::Class::FrozenColumns. But there is caveat: you will not be able to use
'frozen' columns in WHERE clause in SQL.<BR> The idea
is:<BR><BR> package
BaseClass;<BR>
->load_components(qw/DynamicSubclass FrozenColumns
Core/);<BR>
->add_columns(qw/all_columns_that_are_common_to_all_subclasses + type +
data/);<BR> #data must be of type blob or text
(depends on storage engine)<BR>
->typecast_map(type => {1 => 'ClassA', 2 =>
'ClassB'});<BR><BR> package
ClassA;<BR> use parent
'BaseClass';<BR>
->add_frozen|dumped|json_columns(data =>
qw/all_columns_that_are_specific_to_ClassA
for_example/);<BR> <BR> package
MyCode;<BR><BR> my $row = $rs->create({type =>
1});<BR> $row->for_example('hello');
#ok<BR>
$row->type(2);<BR>
$row->for_example('hello'); # error<BR><BR>
$rs->new({ type=> 1, for_example => 'hello' }); #that's ok
too<BR><BR>This is not ideal mechanism, but it quite useful and it helps me
many times.<BR> <BR><BR>
<DIV class=gmail_quote>2009/1/21 Howe, Tom (IDEAS PRACTICE AREAS) <SPAN
dir=ltr><<A
href="mailto:Tom.Howe@morganstanley.com">Tom.Howe@morganstanley.com</A>></SPAN><BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">Further
to my question on inheritance, I have been trying subclassing and the proxy
method options and have a couple of other questions.<BR><BR><BR>First, in an
attempt to try the single flattened style where all Foo object reside in one
table, I tried the cookbook entry on "Dynamic Sub-classing DBIx::Class proxy
classes".<BR><BR>I set up a db table called foo, created a Foo class with an
inflate_result() method and a Foo::Noisy class that inherited from the Foo
class.<BR><BR>I can now create the Foo object and have it inflate into a
Foo::Noisy class.<BR><BR>But, I cant get a Foo::Noisy resultset.<BR><BR>I
thought maybe I could define Foo with only the common columns, then create a
Foo::Noisy subclass that would inherit the columns of Foo and then I could
create a default value for 'type' and use add_columns() to define the
additional NoisyFoo column 'decibels'.<BR><BR>But it seems the only
resultset I can get is for Foo. So anyone creating objects could
inadvertently set a 'colour' for a NoisyFoo or a 'decibel' for
ColouredFoo.<BR><BR><BR><BR><BR><BR>The second thing I tried was to create 3
separate tables for Foo, NoisyFoo and ColouredFoo. Then I created a
Foo::Noisy class with a has_one relationship to the Foo class using a
proxy=>[] defined to allow transparent setting/getting of the
'name'.<BR><BR>This works to a degree in that I can do :<BR><BR>my $nf =
$schema->resultset('Foo::Noisy')->create({id=>1,
decibels=>110});<BR>$nf->name('mynoisyfoo');<BR><BR>But it fails if I
try to do:<BR>my $nf =
$schema->resultset('Foo::Noisy')->create({id=>1, decibels=>110,
name=>'noisyfoo'});<BR><BR>Giving the
error:<BR>DBIx::Class::ResultSet::create(): No such column name on
DB::Foo::Noisy<BR><BR>The proxy doesn't seem to be in affect during
creation.<BR><BR>Also, if I *don't* set the name, I don't get a row in the
Foo table.<BR>Is there a way to enforce that the row is
created?<BR><BR>Otherwise, if I want to search for all Foos, I cant do it on
the common table.<BR><BR>Is there anyway to ensure the Foo row is created
and grn can be passed on create?<BR>
<DIV>
<DIV></DIV>
<DIV class=Wj3C7c><BR><BR><BR><BR><BR>> -----Original
Message-----<BR>> From: Howe, Tom (IDEAS PRACTICE AREAS)<BR>> Sent: 21
January 2009 09:42<BR>> To: DBIx::Class user and developer list<BR>>
Subject: [Dbix-class] Inheritance question..<BR>><BR>> Class structure
is something like this..<BR>><BR><BR>+------+ +------------+
+-------------+<BR>|
Bar |---o| Relation |o - - - - - - | Foo
|abstract<BR>+------+ +------------+
+-------------+class<BR>| id
| | attrs |o
| id |<BR>| name |
+------------+ \_________ | name
|<BR>+------+
\ \ +-------------+<BR>
\ \___^_____
^<BR>
\
| \ |<BR>
\
+------------+ +-------------+<BR>
\| NoisyFoo | | ColouredFoo |<BR>
+------------+ +-------------+<BR>
| id | |
id |<BR>
|
decibels | | color |<BR>
+------------+ +-------------+<BR><BR>>
+-------------+<BR>><BR>> Bar has many Relations<BR>> NoisyFoo has
many Relations<BR>> ColouredFoo has many Relations<BR>> Bar many-many
NoisyFoos<BR>> Bar many-many ColouredFoos<BR>><BR>> (Bar many-many
Foos?)<BR>><BR>><BR>> NoisyFoo and ColouredFoo inherit from
Foo<BR>><BR>> It actually gets more complicated than this
because<BR>> - Bar and Foo both inherit from a base object.<BR>> - All
objects have a unique id are connected via Relation objects<BR>> - The
relation object also contains levels of inheritance<BR>><BR>> I want
to be able to do queries like<BR>><BR>> 1) Given a Bar, find all
related Foo objs<BR>> 2) Given a NoisyFoo or Coloured Foo, find all
related Bars<BR>> 3) For all bars with name matching "%str%" find all
NoisyFoos<BR>> with decibels > '100'<BR>><BR>> Im not sure
whether it would be better to<BR>> a) retain Foo, NoisyFoo and
ColouredFoo as a 3 separate tables,<BR>> b) flatten to 2 tables, so
NoisyFoo and ColouredFoo get their<BR>> own name column<BR>> c)
flatten all Foos to 1 Foo table and create a Type column<BR>> to
differentiate.<BR>><BR>><BR>> Questions:<BR>><BR>> Is
it possible to create Foo, NoisyFoo and ColouredFoo as<BR>> separate
tables (a), then create corresponding DBIx proxy<BR>> classes for them in
such a way that when I create a new<BR>> NoisyFoo row, the 'name' value
is automatically entered into<BR>> the Foo table? And when I retrieve the
row it is<BR>> automatically read in from the Foo
table?<BR>><BR>><BR>> If I were to flatten to 1 table per subclass
(b), how would I<BR>> write a relationship that enabled me to perform
query (1)<BR>> above; find all Foos for a given Bar.<BR>>
--------------------------------------------------------<BR>><BR>>
NOTICE: If received in error, please destroy and notify<BR>> sender.
Sender does not intend to waive confidentiality or<BR>> privilege. Use of
this email is prohibited when received in error.<BR>><BR>>
_______________________________________________<BR>> List: <A
href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class"
target=_blank>http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class</A><BR>>
IRC: <A href="http://irc.perl.org#dbix-class"
target=_blank>irc.perl.org#dbix-class</A><BR>> SVN: <A
href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/"
target=_blank>http://dev.catalyst.perl.org/repos/bast/DBIx-Class/</A><BR>>
Searchable Archive:<BR>> <A
href="http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk"
target=_blank>http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk</A><BR>><BR>--------------------------------------------------------<BR><BR>NOTICE:
If received in error, please destroy and notify sender. Sender does not
intend to waive confidentiality or privilege. Use of this email is
prohibited when received in
error.<BR><BR>_______________________________________________<BR>List: <A
href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class"
target=_blank>http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class</A><BR>IRC:
<A href="http://irc.perl.org#dbix-class"
target=_blank>irc.perl.org#dbix-class</A><BR>SVN: <A
href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/"
target=_blank>http://dev.catalyst.perl.org/repos/bast/DBIx-Class/</A><BR>Searchable
Archive: <A
href="http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk"
target=_blank>http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk</A><BR></DIV></DIV></BLOCKQUOTE></DIV><BR></BLOCKQUOTE></DIV>
<DIV>
<HR>
</DIV>
<P CLASS="BulletedList" STYLE="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; mso-list: none; tab-stops: .5in"><SPAN STYLE="FONT-SIZE: 8pt; COLOR: gray; mso-bidi-font-family: Arial"><FONT FACE="Arial" COLOR="gray" SIZE="1">NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error.</FONT></SPAN></P>
<DIV>
</DIV></BODY></HTML>