This is written in Cookbook:
package My::Schema::User; use base qw/DBIx::Class/; # ->load_components, ->table, ->add_columns, etc. # Make a new ResultSource based on the User class my $source = __PACKAGE__->result_source_instance(); my $new_source = $source->new( $source ); $new_source->source_name( 'UserFriendsComplex' ); # Hand in your query as a scalar reference # It will be added as a sub-select after FROM, # so pay attention to the surrounding brackets! $new_source->name( \<<SQL ); ( SELECT u.* FROM user u INNER JOIN user_friends f ON u.id = f.user_id WHERE f.friend_user_id = ? UNION SELECT u.* FROM user u INNER JOIN user_friends f ON u.id = f.friend_user_id WHERE f.user_id = ? ) SQL # Finally, register your new ResultSource with your Schema My::Schema->register_source( 'UserFriendsComplex' => $new_source ); Next, you can execute your complex query using bind parameters like th +is: my $friends = [ $schema->resultset( 'UserFriendsComplex' )->search( +{}, { bind => [ 12345, 12345 ] } ) ]; ... and you'll get back a perfect L<DBIx::Class::ResultSet>.
But it dosen't work! I produce my class MyClass.pm But without __PACKAGE__->table('fake_table'); It wont startup and says: Can't locate object method "result_source_instance" via package "My::Schema::MyClass" What is it? Wrong example in cookbook!^??? As i see there is no method to exec custom RAW SQL trough DBIx-Class. For executing raw sql cookbook give us a method with little hack - author annotate us generated query will be paste in  "SELECT FROM __YOUR_SQL___ " In my case this is not working because MSSQL Sever don't understand this and it always will be mistaken query for the server. What about it? What do you think? As an alternative way I'm using combination of DBI for call Stored proc saving results in table and ResultSorce to represent table via DBIx. Maybe we can enhance DBIx to executing RAW QUERYS?

In reply to [DBIX::Class] problem with Arbitrary SQL through a custom ResultSource by dreel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.