++ed by:
David Chester

NAME

Norma::ORM::Collection - Queries and results with metadata from classes consuming the Norma::ORM::Mappable role

SYNOPSIS

  my $uk_customers = Norma::ORM::Collection->new(
        class => 'MyApp::Customer',
        where => { country => 'UK' },
  );

  for my $customer ($uk_customers->items) {
        ...
  }

METHODS

new(where => {...} order => $column_name, ...)

Queries the database and returns a collection which contains an array of instantiated objects, along with other metadata. We'll take the following parameters:

join

Specify join clauses as hashrefs, table names (or derived tables / sub queries if you like) pointing to column associations.

  join => [ 
        customer_notes 
                => 'customer_notes.customer_id = customers.id',

        '(select customer_id, min(order_date) first_order_date from orders group by customer_id) first_order_dates' 
                => 'first_order_dates.customer_id = customers.id'
  ]
where

Criteria for the "where" clause may be specified in a number of ways. For simple lookups, key / value pairs will suffice. To find customers in London, you might try:

  where => { 
        city => 'London', 
        country => 'UK',
  }

For comparisons other than equality, sepcify the sql comparison in the key itself. To find customers in Eastern Central London by postcode, you might try:

  where => { 
        'postal_code like' => 'EC%', 
        country => 'UK' 
  }

If you need more flexibility, you can pass in your own where clauses along-with:

  where => [
        q{ postal_code between 'EC2' and 'EC4' },
        { country => 'UK' },
  ]

Outside of custom where clauses, values will be quoted by DBI::quote.

order => $order_clause

Order the query according to this clause, if specified

limit_count

Return this many items

limit_offset

Return items starting at this offset

METHODS

items

Array of objects where each one is an instance of the given $class

total_count

The number of rows that matched this query

query

The actual SQL query that was run

class

The name of the class of the objects returned via items

SEE ALSO

Norma, Norma::ORM::Mappable

AUTHOR

David Chester <davidchester@gmx.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010-2011 by David Chester.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.




Hosting generously
sponsored by Bytemark