[Catalyst] ActiveRecord for Perl

Matt S Trout dbix-class at trout.me.uk
Tue May 22 15:58:32 GMT 2007


On Tue, May 22, 2007 at 06:53:00AM -0700, mreece at vinq.com wrote:
> > On 5/22/07, Adam Bartosik <adam.bartosik at hurra.com> wrote:
> 
> > I doubt there's anything worth porting in ActiveRecord that one of the
> > many Perl options (DBIx::Class, Rose::DB::Object, Class::DBI, Tangram,
> > Alzabo) doesn't provide.
> >
> > - Perrin
> 
> one thing i really like about AR is the association proxies, where
> relationships themselves are objects you can call methods (ie, find) on

DBIC relationships return resultset objects in scalar context:

>   class User < ActiveRecord::Base
>     has_many :items

__PACKAGE__->has_many('items', 'MyApp::DB::Item');

>   end
>   class Item < ActiveRecord::Base
>     belongs_to :user

__PACKAGE__->belongs_to('user', 'MyApp::DB::User');

>   end
> 
>   items = user.items

my @items = $user->items;

or

my $items_rs = $user->items;

>   item = user.items.find(params[:id])

my $item = $user->items->find($item_id);

>   new_item = user.items.create!(params[:item])

my $new_item = $user->items->create(\%item_info);
 
> you can get close to that with RDBO's $user->find_items() (and maybe DBIC
> has something similarish) but the ruby way here feels so much better!

How?

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director    Want a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/             http://www.shadowcatsystems.co.uk/ 



More information about the Catalyst mailing list