[Dbix-class] select * from questions
Gavin Carr
gavin at openfusion.com.au
Fri Apr 28 12:54:44 CEST 2006
On Thu, Apr 27, 2006 at 07:25:37AM -0800, Aran Deltac wrote:
> On 4/27/2006, "Gavin Carr" <gavin at openfusion.com.au> wrote:
> >Just starting to use DBIx::Class in anger for the first time and have
> >a few questions/comments:
> >
> >1. Is there a way of accessing the $schema object from a Row or ResultSet
> >method, or is that a Bad Thing to do? For instance, say per the cookbook
>
> No, its not a bad thing. Here's what you do:
>
> $obj->result_source->schema();
Ah, luverly.
> I just yesterday submitted a fix to the ResultSource docs to show that
> schema is available through it. This may be why you didn't know you
> could do that. :)
That may have had something to do with it. ;-)
> If there is a relationship, then you can just call the methods that your
> relationship created to get at the related objects.
Except that this was in new() before I had an object. Your $schema would have
worked fine though.
> >i.e. related_resultset was just a resultset constructor using a
> >relationship name instead of a table name. Clearly that's wrong, and a
> >'related' resultset involves a join from the original table. This probably
> >needs to be spelled out more clearly in the docs for both related_resultset
> >and search_related. I'm not clear enough about the semantics to have a stab
> >at it myself, but at least the fact that it's a joined resultset should
> >probably be made explicit.
>
> I've not looked at the docs, but to me the method name
> related_resuletset implies a join. But, more verbose docs are rarely a
> bad thing. If you can come up with some extra text that makes this a
> bit more explicit I'd be happy to toss it in to the docs.
Okay, how about just:
related_resultset
Arguments: $relationship_name
Return Value: $resultset
Returns a related (i.e. joined) resultset for the supplied relationship name.
Or more verbosely:
Returns a related resultset for the supplied relationship name. A related
resultset involves a join between the resultsets using the relationship
condition.
> >3. For situations where you have queries that aren't supported by DBIC yet,
> >is there a way to source the underlying Schema dbh for doing statement
> >handles directly, or this not kosher? There's nothing obvious in
> >DBIx::Class::Schema or DBIx::Class::Storage::DBI.
>
> Thats not kosher, since DBIC _should_ handle all situations (although
> there are admitedly a few things it can't do, for now). So, in those
> rare cases, you can get at it with you storage object. Such as
> $obj->result_source->storage->dbh();
Great, thanks. Maybe that method should be documented in
DBIx::Class::Storage::DBI (laced with suitable and dire warnings)?
> >4. Is there an equivalent idiom for overriding ResultSet methods as
> >there is for Row methods in (1) above? I tried something like this:
> >
> >__PACKAGE__->load_components(qw/ ResultSetManager Core /);
> >
> > sub search : ResultSet {
> > my ($self) = shift;
> > my ($cond, $attrs) = @_;
> >
> > $attrs->{order_by} ||= 'name DESC';
> >
> > $self->next::method($cond, $attrs);
> > }
> >
> >but that generates a Class::C3 error:
> >
> > No next::method 'search_like' found for 44285 at /usr/lib/perl5/site_perl/5.8.8/Class/C3.pm line 192
>
> I can't remember, but I know somewhere in the docs there is a section
> that discusses writing your own result sets.
The Cookbook discusses adding new ResultSet methods, but not overriding
them, which is where I got entangled.
Thanks a lot for your answers Aran.
Cheers,
Gavin
More information about the Dbix-class
mailing list