#318 ✓resolved
Martin Frost

DataMapper::Collection not responding to group_by in

Reported by Martin Frost | May 28th, 2008 @ 01:28 AM

Since I updated to (from 0.3.2), DataMapper::Collection seems to be missing the group_by method.

In my merb app, I get this when starting it and trying to look at it in a browser:


~ Loaded DEVELOPMENT Environment...

~ loading gem 'merb-assets' ...

~ loading gem 'merb_helpers' ...

~ loading gem 'dm-timestamps' ...

~ loading gem 'dm-validations' ...

~ Connecting to database...

~ loading gem 'merb_datamapper' ...

~ Please upgrade your Rubygems to the latest version

~ Filter login_required was not found in your filter chain.

~ Compiling routes...

~ Using DataMapper database sessions

~ Using Mongrel adapter

~ Start: Wed May 28 08:22:37 +0200 2008

~ Routed to: {:action=>"index", :controller=>"browser"}

~ Params: {"action"=>"index", "controller"=>"browser"}

~ Cookie set: _session_id => 872db445330e82498e7cba8a9cbf45ac -- {"path"=>"/"}

~ undefined method `group_by' for # - (NoMethodError)

/Library/Ruby/Gems/1.8/gems/dm-core- `method_missing'

/Users/frost/Projects/Reflections/app/controllers/browser.rb:23:in `generate_menu'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/controller/abstract_controller.rb:250:in `send'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/controller/abstract_controller.rb:250:in `_call_filters'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/controller/abstract_controller.rb:242:in `each'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/controller/abstract_controller.rb:242:in `_call_filters'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/controller/abstract_controller.rb:197:in `_dispatch'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/controller/abstract_controller.rb:195:in `catch'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/controller/abstract_controller.rb:195:in `_dispatch'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/controller/merb_controller.rb:197:in `_dispatch'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/dispatch/dispatcher.rb:127:in `dispatch_action'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/dispatch/dispatcher.rb:127:in `synchronize'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/dispatch/dispatcher.rb:127:in `dispatch_action'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/dispatch/dispatcher.rb:74:in `handle'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/rack/application.rb:7:in `call'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/rack/apps/static.rb:22:in `call'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/rack/handler/mongrel.rb:72:in `process'

/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client'

/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'

/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client'

/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'

/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize'

/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'

/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'

/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize'

/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'

/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/rack/adapter/mongrel.rb:22:in `start'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/server.rb:53:in `start'

/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core.rb:87:in `start'


/usr/bin/merb:19:in `load'




Rows 22 through 24 (the generate_menu method) in browser.rb looks like this:

def generate_menu

@galleries_by_category = Gallery.all.group_by {|g| g.category}


I got this from dkubb in the IRC channel:

< dkubb> Frost: right now Collection inherits from LazyArray, which is basically just a wrapper around a regular Array. The first time a kicker method is executed, it loads the data, and sets the Array. As of right now it doesn't delegate everything down to the Array.. just the stuff built into Array. I could make it so it hands everything, including custom stuff like group_by down

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) May 29th, 2008 @ 03:24 AM

    • Milestone cleared.
    • State changed from “new” to “resolved”
    • Assigned user changed from “Sam Smoot” to “Dan Kubb (dkubb)”

    This specific problem should be resolved by the following commit:


    Please add a comment and/or reopen it if the problem is not resolved for you.

  • Martin Frost

    Martin Frost May 29th, 2008 @ 03:33 AM


    Looks neat, but group_by still won't work until I get it mixed into Array, right? And I guess that will be when someone adds it to extlib.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 1st, 2008 @ 06:23 PM

    Martin, that's correct, group_by would need to be mixed into Array or Enumerable for it to be available within Collection. I don't think it's within DataMapper's realm of responsibility to add convenience methods to Array/Enumerable regardless of how useful they are in application code. extlib would be a far better place for such methods.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket