[Dbix-class] Ok, let's begin
Krzysztof Krzyzaniak
eloy at kofeina.net
Tue Sep 20 23:08:32 CEST 2005
Matt S Trout wrote:
> On Tue, Sep 20, 2005 at 10:46:28PM +0200, Krzysztof Krzyzaniak wrote:
>
>>Simple Catalyst app. I have now loaded table in model:
>>
>>package TrackCD::M::DBIC;
>>
>>use strict;
>>use base qw/DBIx::Class/;
>>
>>__PACKAGE__->load_components(qw/Core DB PK::Auto::Pg Table Row
>>Relationship/);
>>__PACKAGE__->connection
>>(
>> TrackCD->config->{'dsn'},
>> TrackCD->config->{'username'},
>> TrackCD->config->{'password'} ,
>> { RaiseError => 1, PrintError => 0, ShowErrorStatement => 1,
>>TraceLevel => 0 }
>>);
>>
>>then in TrackCD::M::DBIC::Record;
>>
>>use strict;
>>use base qw/TrackCD::M::DBIC/;
>>
>>
>>__PACKAGE__->table('record');
>>__PACKAGE__->set_primary_key('rec_id');
>>__PACKAGE__->add_relationship
>>(
>> 'tracks' => 'TrackCD::M::DBIC::Track',
>> {'foreign.rec_id' => 'self.rec_id'}
>>);
>>
>>
>>now in controller I am getting data:
>>
>>my $records = TrackCD::M::DBIC::Record->search
>>(
>> {},
>> {
>> 'order_by' => $orders{$order},
>> 'rows' => 50,
>> 'page' => 1
>> }
>>);
>>
>>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 %]
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