in reply to Search for ORM with Multi-Table-Object Support
Why did you reject DBIC? It's probably what you want. The following is a brief tour of its power.
Pseudo-code which assumes some manual set-up in the schema files (many to many relationships are not discoverable and the example would require overload on the role class to work as shown)–
for my $user ( $users->all ) { print $user->name, $/; print " Roles: ", join(", ", $user->roles) || "none", $/; for my $role ( $user->roles ) { print "Users in this role: "; print join(", ", map { $_->name } $role->role->users); } }
DBIC has notions of the column, the resultset, the table, the record, the connection, the relationships, and more. Many ORMs are record oriented and get ugly/stuck easily since it's all a ball of mud around a row. DBIC handles this really nicely.
my $full_rs = $schema->resultset("user"); my @ids = $full_rs->get_column("id")->all; # -or- my $simple_rs = $full_rs->search({}, { columns => [qw/ id /] }); print $_->id, $/ for $simple_rs->all; # -or, no objects- # use parent "DBIx::Class::ResultSet::HashRef"; <- in resultset class. my $ids = map { $_->{id} } $schema->resultset("user") ->search({},{columns => ["id"]) ->hashref_rs ->all;
The get_column above is an example. DBIx::Class::ResultSetColumn has more, like–
printf "\$%.2f\n", $user->orders->get_column("total")->sum;
Also see the amazing DBIx::Class::Tree::Mobius for an inner-relationship hybrid of nested intervals and materialized paths.
Chained resultsets are everything good in the world. You essentially build up complementary named fragments and make your code compact, syntactical, and fun. For example (assumes you wrote the resultset code, which is easy, to do it)–
$schema->resultset("Company") ->find($id) ->users ->active ->with_overdue_balance;
No. Yes. What?
DBIC supports pretty much everything DBI does. It does not support joining across DBs. You can certainly have a schema instance for each DB exchanging information at the Perl level.
Update: missing adverbly.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Search for ORM with Multi-Table-Object Support
by Xel (Novice) on May 02, 2012 at 21:11 UTC | |
by Your Mother (Archbishop) on May 03, 2012 at 00:52 UTC | |
by preaction (Beadle) on May 02, 2012 at 22:46 UTC | |
by Xel (Novice) on May 03, 2012 at 07:10 UTC | |
by trwww (Priest) on May 03, 2012 at 04:56 UTC |