[Bast-commits] r8395 - in DBIx-Class/0.08/trunk: . lib/DBIx
lib/DBIx/Class/Manual
jhannah at dev.catalyst.perl.org
jhannah at dev.catalyst.perl.org
Thu Jan 21 05:48:14 GMT 2010
Author: jhannah
Date: 2010-01-21 05:48:14 +0000 (Thu, 21 Jan 2010)
New Revision: 8395
Modified:
DBIx-Class/0.08/trunk/Changes
DBIx-Class/0.08/trunk/lib/DBIx/Class.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/FAQ.pod
Log:
Added FAQ: Custom methods in Result classes
Modified: DBIx-Class/0.08/trunk/Changes
===================================================================
--- DBIx-Class/0.08/trunk/Changes 2010-01-21 00:00:07 UTC (rev 8394)
+++ DBIx-Class/0.08/trunk/Changes 2010-01-21 05:48:14 UTC (rev 8395)
@@ -1,5 +1,6 @@
Revision history for DBIx::Class
+ - FAQ "Custom methods in Result classes"
- Perl 5.8.1 is now the minimum supported version
- Subqueries no longer marked experimental
- might_have/has_one now warn if applied calling class's column
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/FAQ.pod
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/FAQ.pod 2010-01-21 00:00:07 UTC (rev 8394)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/FAQ.pod 2010-01-21 05:48:14 UTC (rev 8395)
@@ -433,6 +433,38 @@
=back
+=head2 Custom methods in Result classes
+
+You can add custom methods that do arbitrary things, even to unrelated tables.
+For example, to provide a C<< $book->foo() >> method which searches the
+cd table, you'd could add this to Book.pm:
+
+ sub foo {
+ my ($self, $col_data) = @_;
+ return $self->result_source->schema->resultset('cd')->search($col_data);
+ }
+
+And invoke that on any Book Result object like so:
+
+ my $rs = $book->foo({ title => 'Down to Earth' });
+
+When two tables ARE related, L<DBIx::Class::Relationship::Base> provides many
+methods to find or create data in related tables for you. But if you want to
+write your own methods, you can.
+
+For example, to provide a C<< $book->foo() >> method to manually implement
+what create_related() from L<DBIx::Class::Relationship::Base> does, you could
+add this to Book.pm:
+
+ sub foo {
+ my ($self, $relname, $col_data) = @_;
+ return $self->related_resultset($relname)->create($col_data);
+ }
+
+Invoked like this:
+
+ my $author = $book->foo('author', { name => 'Fred' });
+
=head2 Misc
=over 4
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class.pm 2010-01-21 00:00:07 UTC (rev 8394)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class.pm 2010-01-21 05:48:14 UTC (rev 8395)
@@ -267,6 +267,8 @@
jguenther: Justin Guenther <jguenther at cpan.org>
+jhannah: Jay Hannah <jay at jays.net>
+
jnapiorkowski: John Napiorkowski <jjn1056 at yahoo.com>
jon: Jon Schutz <jjschutz at cpan.org>
More information about the Bast-commits
mailing list