[Dbix-class] Ok, let's begin

Krzysztof Krzyzaniak eloy at kofeina.net
Wed Sep 21 23:33:51 CEST 2005


Matt S Trout wrote:
> On Tue, Sep 20, 2005 at 11:08:32PM +0200, Krzysztof Krzyzaniak wrote:
> 
>>>>and finally I have
>>>>
>>>>DBIx::Class::ResultSet and DBIx::Class::ResultSet->pager. In which way I 
>>>>can use it? (I mean maybe there is some iterator class in ResultSet?)
>>>
>>>
>>>ResultSet *is* an iterator.
>>>
>>>$rs->next will return an object
>>>$rs->all will return all objects in the resultset
>>>$rs->reset does what you expect
>>>$rs->count will count rows (via COUNT(*) without fetching data)
>>>$rs->delete deletes all records in the resultset
>>
>>Woow! It's alive![1]
>>
>>Thank you very much.
>>
>>[1]
>>
>>[% WHILE (record = records.next) %]
>>
>> ... do the Bartman
>>
>>[% END %]
> 
> 
> Plus - $rs->page(1) will return a $rs (or @obj) encapsulating the first page
> of the rs. 'rows' is your search attr to set rows per page.


Ok, part 2.

Standard example, Record & Tracks. Let's train some has_many (it's 
probably different from Class::DBI because example doesn't work).

package TrackCD::M::DBIC::Record;

use strict;
use base qw/TrackCD::M::DBIC/;

__PACKAGE__->table('record');
__PACKAGE__->add_columns (
       qw/rec_id rec_time rec_cddbid rec_artist rec_title rec_notrack 
rec_genre rec_year rec_timestamp/
);

__PACKAGE__->set_primary_key('rec_id');

__PACKAGE__->has_many (
       'tracks' => 'TrackCD::M::DBIC::Track'
);


1;

and tracks:

package TrackCD::M::DBIC::Track;

use strict;
use base qw/TrackCD::M::DBIC/;

__PACKAGE__->table('track');
__PACKAGE__->add_columns(qw/rec_id trck_id trck_title trck_time 
trck_position trck_extinfo/);
__PACKAGE__->set_primary_key('trck_id');

1;

They are connected with 'rec_id' field.

But during loading I have:

Couldn't load "TrackCD::M::DBIC::Record", "Unable to resolve foreign key 
for has_many from TrackCD::M::DBIC::Record to TrackCD::M::DBIC::Track at 
(eval 95) line 3


TrackCD::M::DBIC has definition:

__PACKAGE__->load_components(qw/Core DB PK::Auto::Pg Relationship Table 
Row/);

Any advice?

   eloy
-- 
-------e-l-o-y-----------e-l-o-y- at -t-r-a-n-s-i-l-v-a-n-i-a-.-e-u-.-o-r-g------

        jak to dobrze, że są oceany - bez nich byłoby jeszcze smutniej



More information about the Dbix-class mailing list