X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FFAQ.pod;h=464040dad4b23a031fdb765a758051fb5e9b458e;hb=6aafb6a62ca556f2d34cab164425a401b7ffe8cd;hp=7ec01da6c318d5b74a27a4c1c994624cf319b875;hpb=3e89f28464935f047192dd444a0346c31c3865a2;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Manual/FAQ.pod b/lib/DBIx/Class/Manual/FAQ.pod index 7ec01da..464040d 100644 --- a/lib/DBIx/Class/Manual/FAQ.pod +++ b/lib/DBIx/Class/Manual/FAQ.pod @@ -126,7 +126,7 @@ allow you to supply a hashref containing the condition across which the tables are to be joined. The condition may contain as many fields as you like. See L. -=item .. define a relatiopnship across an intermediate table? (many-to-many) +=item .. define a relationship across an intermediate table? (many-to-many) Read the documentation on L. @@ -182,15 +182,9 @@ attribute. See L. =item .. sort my results based on fields I've aliased using C? -You don't. You'll need to supply the same functions/expressions to -C, as you did to C attribute, such as: - - ->search({}, { select => [ \'now() AS currenttime'] }) - -Then you can use the alias in your C attribute. +You didn't alias anything, since L +B with the produced SQL. See +L for details. =item .. group the results of my search? @@ -199,15 +193,7 @@ attribute, see L. =item .. group my results based on fields I've aliased using C? -You don't. You'll need to supply the same functions/expressions to -C, as you did to C attribute, such as: - - ->search({}, { select => [ \'now() AS currenttime'] }) - -Then you can use the alias in your C attribute. +You don't. See the explanation on ordering by an alias above. =item .. filter the results of my search? @@ -433,6 +419,38 @@ data out. =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 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 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 @@ -609,7 +627,7 @@ Likely you have/had two copies of postgresql installed simultaneously, the second one will use a default port of 5433, while L is compiled with a default port of 5432. -You can chance the port setting in C. +You can change the port setting in C. =item I've lost or forgotten my mysql password