named_scope

47 views
Skip to first unread message

et...@maven-soft.com

unread,
Dec 31, 2009, 12:13:36 PM12/31/09
to MongoMapper
Is named_scope available with MongoMapper? If so, what do you need to
do in order to use them? Simply calling named_scope doesn't seem to
work like it did in ActiveRecord.

Here is the class and resulting error:

class CommitFile
include MongoMapper::EmbeddedDocument

key :commit_id, ObjectId
key :filename, String
key :diff, String
key :state, String

belongs_to :commit
has_many :comments

named_scope :added, :conditions => {:state => 'added'}, :order =>
'filename'
named_scope :removed, :conditions => {:state => 'removed'}, :order
=> 'filename'
named_scope :modified, :conditions => {:state => 'modified'}, :order
=> 'filename'
end

undefined method `named_scope' for CommitFile:Class (NoMethodError)

Lance Carlson

unread,
Dec 31, 2009, 8:41:36 PM12/31/09
to mongo...@googlegroups.com, MongoMapper
Named scopes do not work in mongomapper. I think it would be a cool
feature. I just wrote an adapter for the AASM gem and the activerecord
version inculdes a bunch of support for named scopes. Would be nice to
be able to port these over as well.

Sent from my iPhone

On Dec 31, 2009, at 12:13 PM, "et...@ethangunderson.com" <et...@maven-soft.com
> wrote:

> --
> You received this message because you are subscribed to the Google
> Groups "MongoMapper" group.
> For more options, visit this group at
> http://groups.google.com/group/mongomapper?hl=en?hl=en

John Nunemaker

unread,
Jan 1, 2010, 1:31:15 AM1/1/10
to mongo...@googlegroups.com
Someone has been working on it. I also have ideas. Not in there right now.

Kyle Banker

unread,
Jan 4, 2010, 10:41:32 AM1/4/10
to mongo...@googlegroups.com
One thing nice thing about mongo is that queries are basically chainable. To add a scope, just add to the query selector document. So named_scope should be quite a bit less complicated here than with the sql.

Steven Garcia

unread,
Jan 4, 2010, 11:27:55 AM1/4/10
to MongoMapper
You can find named_scope in this branch:

http://github.com/mattbeedle/mongomapper/commits/master

John Nunemaker

unread,
Jan 4, 2010, 11:47:27 AM1/4/10
to mongo...@googlegroups.com
I don't think that branch has any tests and is a direct port of AR which doesn't make sense to me. Unless it has changed since I looked at it or I'm thinking of something else.

I have plans for named scope type stuff in MM but it will be a few releases.

On Mon, Jan 4, 2010 at 11:27 AM, Steven Garcia <steven...@gmail.com> wrote:
You can find named_scope in this branch:

http://github.com/mattbeedle/mongomapper/commits/master

--

mattbeedle

unread,
Feb 19, 2010, 12:55:01 PM2/19/10
to MongoMapper
Yes, that's right, I just directly ported across named_scope from
activerecord, and hacked it in without tests in a hurry so I could
proceed with a current project. I wouldn't recommend anyone actually
using that branch, there are definitely a few problems with it.

On Jan 4, 5:47 pm, John Nunemaker <nunema...@gmail.com> wrote:
> I don't think that branch has any tests and is a direct port of AR which
> doesn't make sense to me. Unless it has changed since I looked at it or I'm
> thinking of something else.
>
> I have plans for named scope type stuff in MM but it will be a few releases.
>

Reply all
Reply to author
Forward
0 new messages