Re: [Dbix-class] Can't find source for XXX question SOLVED

2018-12-03 Thread ejm
Hi all,

In case anyone else has the issue of "Can't find source for XXX", my solution 
was to correct
the value of source_name.

I was specifying source_name in my Result class pkg to be the table name in the 
DB.  
After looking at the code in DBIx::Class::Schema and the POD documentation, it 
seems that source_name should be the
final part of the class name for the corresponding Result class for that table.

Once I changed the value of source_name, the query worked fine, returning all 
the expected data.

In my example, the change was:

package X::Y::Z::Result::Table1;
use base qw(DBIx::Class::Core);

... other Perl statements (strict, warnings, etc.)

__PACKAGE__->table('table1');
__PACKAGE__->resultset_class('X::Y::Z::ResultSet::Table1');
__PACKAGE__->source_name('Table1');  <--- table1 
changed to Table1


... Accessor statements

1;

In my codebase, X::Y::Z represents the nested namespaces in the existing 
(large) Apache codebase that I am adding
DBIx functionality.



Thanks and regards,

--Ed

___
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/dbix-class@lists.scsys.co.uk


Re: [Dbix-class] [DBIx-class] Can't find source for XXX question SOLVED

2018-12-03 Thread ejm
Hi all,

In case anyone else has the issue of "Can't find source for XXX", my solution 
was to correct
the value of source_name.

I was specifying source_name in my Result class pkg to be the table name in the 
DB.  
After looking at the code in DBIx::Class::Schema and the POD documentation, it 
seems that source_name should be the
final part of the class name for the corresponding Result for that table.

Once I changed the value of source_name, the query worked fine, returning all 
the expected data.

In my example, the change was:

package X::Y::Z::Result::Table1;
use base qw(DBIx::Class::Core);

... other Perl statements (strict, warnings, etc.)

__PACKAGE__->table('table1');
__PACKAGE__->resultset_class('X::Y::Z::ResultSet::Table1');
__PACKAGE__->source_name('Table1');  <--- table1 
changed to Table1


... Accessor statements

1;

In my codebase, X::Y::Z represents the nested namespaces in the existing 
(large) Apache codebase that I am adding
DBIx functionality.



Thanks and regards,

--Ed


___
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/dbix-class@lists.scsys.co.uk


Re: [Dbix-class] Can't find source for XXX question

2018-12-01 Thread Mitchell Elutovich
If the data is coming from the DB it does not use the "new" sub it uses a
sub inflate_result.

Start by looking at these

(search for inflate_result)
https://metacpan.org/pod/distribution/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod

https://metacpan.org/pod/DBIx::Class::Row#inflate_result


On Fri, Nov 30, 2018 at 12:58 AM ejm  wrote:

> Hi All,
>
> Another newbie question about the "Can't find source for XXX" error
> message.
>
> I've been able to establish a connection to my MySQL DB by specifying a
> storage type for my Schema,
> but I keep getting the "Can't find source for XXX" error message when I
> try searching the table XXX.
>
> In my Schema object I have :
>
> __PACKAGE__->load_namespaces();
>
> and the usual "use base qw(DBIx::Class::Schema);
>
> so that methods are correctly inherited from DBIx::Class::Schema.
>
> Then I have a new constructor in my Schema object which blesses my object
> in the namespace I need it in:
>
> sub new {
> my ($proto, $db) = @_;
> my $class = ref($proto) || $proto;
> my $self = bless {}, $class;
>
> $self->storage_type('::DBI::mysql');
> return $self->connect($dsn, $dbuser, $dbpw, { AutoCommit => 1});
> }
>
> where $db is the MySQL DB I need to access and $dbuser, $dbpw are local
> variables containing the usual User and PW.
>
> and $dsn = "dbi:mysql:database=$db";
>
> I've checked the object returned by the constructor and it has the
> expected entries:
>
> class_mappings => { 'X::Y::Z::Result::Table1' => 'Table1',
> 'X::Y::Z::Result::Table2' => 'Table2',
>  ...
>},
>
> source_registrations => {
>   'Table1' => bless( { 'result_class' =>
> 'X::Y::Z::Result::Table1',
>'resultset_class' =>
> 'X::Y::Z::ResultSet::Table1',
>'name' => 'Table1',
>'source_name' => 'Table1',
> ...
>   },
> 'DBIx::Class::ResultSource::Table'},
>
>   ...
>  },
>
> storage => { '_connect_info' => [ 'dbi:mysql:database=VSO',
>   'dbuser',
>   'dbpw',
>   {
> 'AutoCommit' => 1
>   },
>  '_conn_pid' => 10779,
>  ...
>
> }
>
>
> I see an entry in source_registrations for each of the tables in the DB
> VSO, all with their correct columns.
> However, I noted that the objects are all blessed into the generic
> DBIx::Class::ResultSource::Table class and not
> the X::Y::Z::ResultSource::Table1 class as I would have expected.
>
> Is that why I am getting the "Can't find source ..." error message ?
>
> I have a package for each table in X::Y::Z::Result namespace and
> additionally a package for the table I am testing
> in both X::Y::Z::ResultSource::Table1 and X::Y::Z::ResultSet::Table1
>
> I noted that the resultset_class key above was indeed set to my
> namespace-specific package for my test table.
>
> Any tips or ideas would be greatly appreciated.
>
>
> Thanks,
>
> --Ed
>
>
>
>
>
>
>
> ___
> 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/dbix-class@lists.scsys.co.uk
>
___
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/dbix-class@lists.scsys.co.uk

[Dbix-class] Can't find source for XXX question

2018-11-29 Thread ejm
Hi All,

Another newbie question about the "Can't find source for XXX" error message.

I've been able to establish a connection to my MySQL DB by specifying a storage 
type for my Schema,
but I keep getting the "Can't find source for XXX" error message when I try 
searching the table XXX.

In my Schema object I have :

__PACKAGE__->load_namespaces();

and the usual "use base qw(DBIx::Class::Schema);

so that methods are correctly inherited from DBIx::Class::Schema.

Then I have a new constructor in my Schema object which blesses my object in 
the namespace I need it in:

sub new {
my ($proto, $db) = @_;
my $class = ref($proto) || $proto;
my $self = bless {}, $class;

$self->storage_type('::DBI::mysql');
return $self->connect($dsn, $dbuser, $dbpw, { AutoCommit => 1});
}

where $db is the MySQL DB I need to access and $dbuser, $dbpw are local 
variables containing the usual User and PW.

and $dsn = "dbi:mysql:database=$db";

I've checked the object returned by the constructor and it has the expected 
entries:

class_mappings => { 'X::Y::Z::Result::Table1' => 'Table1', 
'X::Y::Z::Result::Table2' => 'Table2',
 ...
   },

source_registrations => {
  'Table1' => bless( { 'result_class' => 
'X::Y::Z::Result::Table1',
   'resultset_class' => 
'X::Y::Z::ResultSet::Table1',
   'name' => 'Table1',
   'source_name' => 'Table1',
...
  }, 
'DBIx::Class::ResultSource::Table'},

  ...
 },

storage => { '_connect_info' => [ 'dbi:mysql:database=VSO',
  'dbuser',
  'dbpw',
  {
'AutoCommit' => 1
  },
 '_conn_pid' => 10779,
 ...

}


I see an entry in source_registrations for each of the tables in the DB VSO, 
all with their correct columns.
However, I noted that the objects are all blessed into the generic 
DBIx::Class::ResultSource::Table class and not
the X::Y::Z::ResultSource::Table1 class as I would have expected.

Is that why I am getting the "Can't find source ..." error message ?

I have a package for each table in X::Y::Z::Result namespace and additionally a 
package for the table I am testing
in both X::Y::Z::ResultSource::Table1 and X::Y::Z::ResultSet::Table1

I noted that the resultset_class key above was indeed set to my 
namespace-specific package for my test table.

Any tips or ideas would be greatly appreciated.


Thanks,

--Ed







___
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/dbix-class@lists.scsys.co.uk