Brandon Black wrote:
On 6/6/07, John Goulah <[EMAIL PROTECTED]> wrote:
> > From DBIx::Class::Manual::Cookbook
> >
(http://search.cpan.org/~mstrout/DBIx-Class-0.07000/lib/DBIx/Class/Manual/Cookbook.pod#Retrieving_a_row_object
> > )
> > my $schema = $cd->result_source->schema;
> > my $artist_rs = $schema->resultset('Artist');
Actually this gets the schema, and the resultset object out of that.
The
object that comes out of this is the same object that is returned from
search. The only reason I posted back is b/c I thought someone else may
benefit from the fact that you can get this out of there if you need
to for
some reason, in my case, I'll just use search.
But it doesn't do what you think it does. Those two lines of code get
you the resultset object for the entire "Artist" table, not for your
one row.
Really? I wouldn't have thought that myself. That doesn't seem to do
what I'd expect.
Is "find" then, what "retrieve" is to CDBI ?
It seems like there is a way to make everyone on this thread happy.
The documentation implies that you CAN specify your own where clauses
for searches so you can narrow down your search if you want, and still
use regular old SQL (using search_literal):
-- warning, I lifted this directly from the person I am posting back to
;) --
http://search.cpan.org/~blblack/DBIx-Class-0.07006/lib/DBIx/Class/Manual/Intro.pod#Finding_your_objects
ie.,
# Find Peter Frampton albums from the year 1986
my $where = 'artist = ? AND year = ?';
my @bind = ( 'Peter Frampton', 1986 );
my $rs = $schema->resultset('Album')->search_literal( $where, @bind );
Because I think the underlying issue is THIS is really much more cumbersome
than the corresponding SQL statement:
my $rs = $schema->resultset('Album')->search({
artist => { '!=', 'Janis Joplin' },
year => { '<' => 1980 },
albumid => { '-in' => [ 1, 14, 15, 65, 43 ] }
});
So, if you used "search_literal" you could return the row as an object, no?
-frank
--
Frank Speiser
CTO
TAKKLE, Inc.
[EMAIL PROTECTED]
_______________________________________________
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]/