#!/usr/bin/perl -w

use strict;
use Data::Dumper;

use lib '/home/uwe/tmp/cvs/rose/modules/Rose-DB/lib';
use Rose::DB;
use lib '/home/uwe/tmp/cvs/rose/modules/Rose-DB-Object/lib';
use Rose::DB::Object::Manager;

BEGIN {
    Rose::DB->register_db(domain   => 'default',
                          type     => 'default',
                          driver   => 'mysql',
                          database => 'Rose',
                          username => 'uwe',
                          password => 'uwe',
                         );
}

use lib './lib';
use Category;
use Price;
use Product;


my %query = (
             'prices.region' => 'DE',
            );
my %rose  = (object_class    => 'Product',
             require_objects => [qw(prices)],
             #with_objects    => [],
             clauses         => [],
             query           => [%query],
             sort_by         => 'products.id',
             #multi_many_ok   => 1,
            );

my $count = Rose::DB::Object::Manager->get_objects_count(%rose);
printf("COUNT: %d\n\n", $count);

get_objects(%rose); # 1 and 2

print "---------------\n\n";

$rose{limit}  = 1;
$rose{offset} = 0;
get_objects(%rose); # 1 - product1

$rose{limit}  = 1;
$rose{offset} = 1;
get_objects(%rose); # 2 - product2 -> but it is: 1 - product1

$rose{limit}  = 1;
$rose{offset} = 2;
get_objects(%rose); # should be empty


sub get_objects {
    my %rose = @_;

    my $products = Rose::DB::Object::Manager->get_objects(%rose);

    foreach my $product (@$products) {
        printf("ID:    %d\n", $product->id);
        printf("NAME:  %s\n", $product->name);
        print "\n";
    }
}
