Hi Peter
On 01/21/2012 03:27 PM, Peter Rabbitson wrote:
Vangelis Katsikaros wrote:
Hello
I had a problem following the instructions in "Arbitrary SQL through a
custom ResultSource" [1] since it gave me an error of `Can't locate
object method "result_source_instance"`
I found a solution in this perlmonk answer [2]. Indeed this works:
<code>---------------------------
package Dir::Dir::ComplexQuery;
use strict;
use base 'DBIx::Class::Core';
__PACKAGE__->table( 'dummy_table_name' );
__PACKAGE__->add_columns( qw/col1 col2 col3/ );
__PACKAGE__->result_source_instance->name( \q!(complex SQL ... )! );
</code>---------------------------
and I can normally do:
...->resultset('ComplexQuery')->search();
My questions are the following:
1. The function "table" is the one from
DBIx::Class::ResultSourceProxy::Table as described in [3], right? I am
using `DBIx::Class::Schema::Loader` so I never had created a DBIx
"class table" myself.
Yes. What you witnessed is a side effect of a long standing wart.
This will be solved in the next release or two (bogus ->table calls
will no longer be needed). I could explain why this is currently
necessary, but I rather not since 1) this code is not for the faint
of heart and 2) it is entirely going away. I will however elaborate
more if you express further interest.
Thanks for offering to explain in depth, but I think there is no need to
elaborate on this - your arguments are clear. Use this time more
productively :)
2. The "__PACKAGE__->table('table_name')" will NOT trigger a creation
of this table (in this case it's a view) to the actual DB, correct?
Or is there a scenario where the creation of a view hac be triggered
and I can end up with a view named 'dummy_table_name' in my DB?
Creation is not something that ever happens automatically in DBIC.
Such a table definition *may* be included in a subsequent call to
deploy(), unless you follow the new improved way of doing things to
which Wolfgang already pointed you.
3. In which DBIx package is "result_source_instance" defined? I did
searched but I couldn't find it - maybe I am not searching the right way.
See the answer to point 1, in particular this is one of the "not for
the faint of heart" references (the method is created at runtime, per
class, depending on certain conditions).
Thanks for all the answers,
Vangelis
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]