I have written a small paragraph that clarifies (I hope :-) why DBIC has
no "stringify_self" method or "Stringify" column group.
This obviously intended for DBIC newcomers coming from CDBI...
--
Marcello Romani
Responsabile IT
Ottotecnica s.r.l.
http://www.ottotecnica.com
--- FAQ.pod 2006-08-18 13:00:27.000000000 +0200
+++ FAQ_modified.pod 2006-09-07 12:09:23.000000000 +0200
@@ -324,3 +324,43 @@
you ask the resultset for an actual row object.
=back
+
+=head2 Notes for CDBI users
+
+=over 4
+
+=item Is there a way to make an object auto-stringify itself as a particular
column or group of columns (a-la cdbi Stringfy column group, or stringify_self
method) ?
+
+Perl already offers a method to make an object stringify itself, through the
C<use overload> pragma.
+
+Therefore there is no need for a specialized stringification method like
C<stringify_self>.
+
+B<Quick example:>
+
+ use overload "" => sub { $_[0]->name . ", " . $_[0]->address }
+
+
+B<Scenario:>
+
+Suppose we have two tables: C<Product> and C<Category>. The table
specifications are:
+
+ Product(id, Description, category)
+ Category(id, Description)
+
+C<category> is a foreign key into the Category table.
+
+If you have a Product object C<$obj> and write something like
+
+ print $obj->category
+
+things will not work as expected.
+
+To obtain, for example, the category description, you should add this method
to the class mapping the Category table (tipically C<DB::Main::Category>):
+
+ use overload "" => sub {
+ my $self = shift;
+
+ return $self->Description;
+ }
+
+=back
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/