jnunemaker / mongomapper
- Source
- Commits
- Network (102)
- Issues (14)
- Downloads (31)
- Wiki (5)
- Graphs
-
Branch:
master
-
"save" lies when a document violates a unique index
2 comments Created 6 days ago by mrkurtTo reproduce:
- Create a unique index on a field
- Save one document
- Save another document with the same value in the unique field
- Note that "save" returns "true", but the 2nd document does not exist in mongo
It looks like fixing this might be as simple as passing :safe => true to the underlying save method, then catching the exception. I don't know what other implications there are to doing that, though.
Comments
-
New keys defined in the model are not propagated in the existing documents
3 comments Created 6 days ago by rhyhannWhen I add a key in an existing model, the previously created objects are not updated. A demonstration is worth a thousand words:
>> require 'mongo_mapper' => true >> MongoMapper.database = 'itsatest' => "itsatest" >> class Person >> include MongoMapper::Document >> key :first_key >> end => #<MongoMapper::Key:0x101fe92a8 @name="first_key", @type=nil, @default_value=nil, @options={}> >> first = Person.new(:first_key => 'first_value') => #<Person _id: nil, first_key: "first_value"> >> first.save => true >> class Person >> key :second_key >> end => #<MongoMapper::Key:0x101fd50c8 @name="second_key", @type=nil, @default_value=nil, @options={}> >> Person.new => #<Person second_key: nil, _id: nil, first_key: nil> >> first.second_key = 'second_value' MongoMapper::KeyNotFound: Could not find key: "second_key" from /Library/Ruby/Gems/1.8/gems/mongo_mapper-0.6.8/lib/mongo_mapper/embedded_document.rb:361:in `read_attribute' from /Library/Ruby/Gems/1.8/gems/mongo_mapper-0.6.8/lib/mongo_mapper/dirty.rb:78:in `send' from /Library/Ruby/Gems/1.8/gems/mongo_mapper-0.6.8/lib/mongo_mapper/dirty.rb:78:in `clone_key_value' from /Library/Ruby/Gems/1.8/gems/mongo_mapper-0.6.8/lib/mongo_mapper/dirty.rb:118:in `write_attribute' from (eval):10:in `second_key=' from (irb):13 >> first => #<Person _id: 4b3345d833e0ad021d000001, first_key: "first_value">Comments
jnunemaker
Wed Dec 30 11:25:34 -0800 2009
| link
I don't know that I'm worried about this. If you loaded first from the database after the key was added it would work fine. What is a valid use case for reopening the class, adding a new key and then having it propogate to things that were already initialized?
Well, this behaviour could have the dynamic keys use case. The fact is that I didn't know about dynamic keys, which replaces this very well, so just close the issue please. My mistake.
For example, one could define an empty Post class that plugins would use -- for example, a Tags plugin -- by adding keys into it. But it could be done in the launching, so that this problem does not occur.
jnunemaker
Wed Dec 30 13:53:03 -0800 2009
| link
K. Closed.
-
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:in `load_missing_constant':NameError: uninitialized constant Mongo::InvalidStringEncoding
Ran across this error while trying to use mongomapper and grip to save mp3 files to gridfs. At first I was getting TypeError: no c encoder for this type yet (14), which I twittered, and someone said to install the ruby mongo driver from source and it would fix that problem. After updating the ruby driver it breaks mongomapper.
Comments
jnunemaker
Tue Dec 22 08:40:06 -0800 2009
| link
That is the mongo ext gem. You have to make sure you have the same version of mongo and mongo ext.
-
[validatable] errors do not accept a default string
4 comments Created 9 days ago by bitzestyfor example devise calls
errors.add(:email, :already_confirmed, :default => 'already confirmed')which raises an argument error (3 for 2)
Comments
jnunemaker
Mon Dec 21 11:47:48 -0800 2009
| link
I don't see any immediate reason to add this. Seems like devise should just have error adding abstracted as it has the storage part abstracted. Thoughts?
possibly, however it's not the first gem I've used that as raised this exception (just hacked the others to comply) if you take a look at the AR docs seems that
adddoes take an options hash, it would be nice to mimic the api for compatibility.
http://api.rubyonrails.org/classes/ActiveRecord/Errors.html#M002201
jnunemaker
Mon Dec 21 12:32:57 -0800 2009
| link
I only care about compatibility where it makes sense. Is this for internationalization or why would you ever pass an error message like that?
-
Create :symbol.asc and .desc for ordering with style
1 comment Created 10 days ago by jnunemaker:order => :foo.desc
Comments
jnunemaker
Wed Dec 30 13:29:53 -0800 2009
| link
You can now order using symbol operators. :order => :foo.asc or :order => [:foo.asc, :bar.desc]. Closed by 1c10c5c.
-
$where allows injection of bad things. Better to use case insensitive regex search here.
Comments
jnunemaker
Wed Dec 30 12:15:48 -0800 2009
| link
Switched case sensitive uniqueness check to use regex instead of $where to prevent any possible injection. Closed by 831b3fe.
-
BlogPost.first(:parent_id => parent_id, :published_at.gte => published_at.utc, :id.ne => id, :order => 'published_at')
Should convert the id to _id but it doesn't.
Comments
jnunemaker
Wed Dec 30 12:33:13 -0800 2009
| link
:id with operator now converts to :_id. Closed by 684cd1f.
-
>> Admin.destroy_all src/tcmalloc.cc:186] Attempt to free invalid pointer: 0x2069d0 Abort trapon REE ruby 1.8.6 (2008-08-11 patchlevel 287)
Comments
jnunemaker
Tue Dec 15 09:09:56 -0800 2009
| link
Are you doing the connect_to_master stuff in the initializer? Did you try doing the destroy_all from console? Pretty sure this is not an MM issue.
ah, is the connection not made if you go through the console?
jnunemaker
Tue Dec 15 09:15:15 -0800 2009
| link
Pretty sure this is not MM can we continue this on the mailing list (groups.google.com/group/mongomapper)? It is easier to respond there as I can just reply to email. Just post same question and I'll respond.
-
Convert dates in queries to utc if they aren't
1 comment Created 16 days ago by jnunemakerRight now you have to pass utc dates to queries for them to work. This would let mm do the work if you forget.
Comments
jnunemaker
Mon Dec 14 13:36:08 -0800 2009
| link
duplicate, clicked submit twice.
-
Time fields don't save hours and minutes correctly
5 comments Created 17 days ago by retroWhen saving time fields (including timestamps), date is saved correctly but time parameters are changed to '00:00:00'
Comments
jnunemaker
Sun Dec 13 09:13:44 -0800 2009
| link
I'm not seeing this at all. Just did a tiny test to double check.
I can't duplicate it with this test. But it still happens inside of my Rails app. I'm very confused with why is this happening. After I do some more tests, I'll send test case.
jnunemaker
Sun Dec 13 10:19:13 -0800 2009
| link
do you have any callbacks or anything that are adjusting things? if you could post as much as possible of your models in a gist or something that would help.
jnunemaker
Sun Dec 13 10:19:39 -0800 2009
| link
might be better to post on mailing list the gist instead of here as i've never seen this behavior.
-
Current mongomapper gem is 0.4.2 and depends on mongodb-mongo 0.14.1, which in edition to being out of date, cannot coexist with mongo_ext 0.18.1.
Comments
jnunemaker
Thu Dec 10 07:11:44 -0800 2009
| link
The gem has been renamed to mongo_mapper for a while now. It is mentioned in the readme. Be sure to check stuff like that out or email the mailing list (groups.google.com/group/mongomapper) before creating issues. :)
gem install mongo_mapper will get you what you want.
-
I'm trying to add this example hash to an embedded document, and on create the mongo driver's ObjectID.from_string is being called on it.
{"action"=>"show", "id"=>"3", "controller"=>"transactions"}
The conflict is with the "id" field. This was working in an older version of MM prior to 0.6.0.
I assumed that there might be an implicit _id but there seems to be a conflict.
Comments
It may actually be when reading from the database, if there is an "id" field along with the _id.
I think the conflict happens on assignment because the method id= is actually used to write to the _id field.
Seems to be resolved in my application by removing EmbeddedDocument#id and renaming #id= to #_id=.
This may be a bad idea.
jnunemaker
Wed Dec 09 09:47:47 -0800 2009
| link
Yeah, that is a bad idea. id and id are basically the same thing. The only difference is that id is what gets stored in the db. id and id= are shortcut methods to work with id as id is kind of ugly. Just use a key other than id and you'll be fine.
This is for Mongolytics, I don't quite have control over the fields being used. I suppose I could check for "id" as a reserved word and change it to something else but, that's confusing to look at when a request is logged with an "id" (as is common in Rails) and comes out with an "ident" or something else. I might change my own and just live with the ugly name "_id=".
-
$ rake spec:models --trace (in /Users/arie/railsproject) Invoke spec:models (first_time) Invoke db:test:prepare (first_time) Invoke db:abort_if_pending_migrations (first_time) Invoke environment (first_time) Execute environment Execute db:abort_if_pending_migrations rake aborted!
ActiveRecord::ConnectionNotEstablished
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:326:inretrieve_connection' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:inretrieve_connection' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:inconnection' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/migration.rb:435:ininitialize' /opt/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/tasks/databases.rake:197:innew' /opt/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/tasks/databases.rake:197 /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:incall' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:inexecute' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:ineach' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:inexecute' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:ininvoke_with_call_chain' /opt/local/lib/ruby/1.8/monitor.rb:242:insynchronize' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:ininvoke_prerequisites' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:ineach' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:ininvoke_prerequisites' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:ininvoke_with_call_chain' /opt/local/lib/ruby/1.8/monitor.rb:242:insynchronize' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:ininvoke_prerequisites' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:ineach' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:ininvoke_prerequisites' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:ininvoke_with_call_chain' /opt/local/lib/ruby/1.8/monitor.rb:242:insynchronize' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:ininvoke' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:ininvoke_task' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:intop_level' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:ineach' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:intop_level' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:intop_level' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:inrun' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:inrun' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31 /opt/local/bin/rake:19:in `load' /opt/local/bin/rake:19$ cat config/environment.rb = '2.3.5' unless defined? RAILS_GEM_VERSION require File.join(File.dirname(FILE), 'boot')
Rails::Initializer.run do |config|
config.gem 'mongo_mapper' config.gem 'haml' config.frameworks -= [:active_record] config.time_zone = 'UTC' config.i18n.default_locale = :id endMongoMapper.database = "railsproject-#{Rails.env}"
Wondering where else I could ask this after searching jnunemaker mongomapper mailing list ...
Comments
jnunemaker
Wed Dec 09 09:48:27 -0800 2009
| link
groups.google.com/group/mongomapper. Not sure that this is an MM issue.
-
reload should reset the document rather than return a new document
3 comments Created 27 days ago by michaeldwanReload returns a new document which is different than the ActiveRecord behavior of resetting the current object.
Looking at the tests, the convention with MM is to do:
doc = @document.create(:phrase => 'Foo') doc = doc.reload doc.changed?.should be_falseI propose we change it to be more ActiveRecord like:
doc = @document.create(:phrase => 'Foo') doc.reload doc.changed?.should be_falseI'll be adding support for that in my fork and send out a pull request soon.
Comments
jnunemaker
Wed Dec 09 09:49:31 -0800 2009
| link
agreed. the current implementation was just to get something working. basically all associations and key instance variables need to be set to nil probably.
jnunemaker
Sat Dec 12 19:40:53 -0800 2009
| link
now works correctly in master and will go out with next release.
michaeldwan
Sun Dec 13 09:51:59 -0800 2009
| link
Awesome John!
-
how to def initialize in my classes that include MongoMapper::Document
2 comments Created about 1 month ago by davorinrusevljanhi, if I define initialize method in my data classes that include Document, instances no longer correctly load. (since MongoMapper does not have chance to do its magic)
basically I would like to have something like Person.new('myname') working together with MM
how to achieve that?
Comments
jnunemaker
Mon Nov 30 11:25:06 -0800 2009
| link
yep. initialize needs to always work with a hash if one is given. overriding and using super is the only way.
-
When a model belongs_to embedded model (EmbeddedDocument), MongoMapper throws
class Comment include MongoMapper::EmbeddedDocument { ... } end class Video include MongoMapper::Document { ... } key :comment_id belongs_to :comment end # => video.comment undefined method `find_by_id' for Comment:ClassComments
jnunemaker
Tue Nov 24 07:38:17 -0800 2009
| link
I don't know modeling it this way is a good idea. If something is going to belong to something else, it really should be a full fledged document. Why not just store the video id in the comment?
In this case video's comment_id may be changed by the user later. That's why it belongs_to comment.
Also, comments are embedded into the User model. In my application Videos are also embedded into the User, actually. Just simplified the example.
jnunemaker
Wed Dec 09 09:51:03 -0800 2009
| link
Don't know that I'll ever make embedded docs work like this. Just write a bit of ruby to for the association like methods (ie: setting and getting comment id) and use those instead of trying to use belongs_to.
-
The dirty capability is available only in MongoMapper::Document.
I add capability to dirty in MongoMapper::EmbeddedDocument too.
My patch is on http://github.com/shingara/mongomapper/commit/bee324b44259c2f4759337da8fed058f206bc543
Any feedback are welcome.
Comments
jnunemaker
Sun Dec 20 11:30:11 -0800 2009
| link
Created a ticket that explains how I'd like to see this done #129. Will work on it at some point. Closing this as now it is a duplicate.
-
There are no callback in EmbeddedDocument like report on ticket #73. So we can't use validation. there are no validation insert in EmbeddedDocument failing the save. But we can add this methods.
So we can avoid using this useless method or add callback in EmbeddedDocument.
Comments
jnunemaker
Mon Nov 16 21:43:24 -0800 2009
| link
You can use validation, you just have to do it from root document. I think there is something in validatable that is like include_errors_from. Also, you can just make a valid method that runs through all embedded docs and validates them.
I haven't put this into MM because I can see situations when this would suck if you had a lot of embedded documents and I can't say that I have a good idea for how all those errors should be combined. I figure if you need validations on embedded docs you can just use validate callbacks on the root document.
Well, if you don't run validations on an embedded document, why have validations on it in the first place? You can't make an embedded document in isolation, can you? I mean, once you add an embedded document to a document, it becomes part of that document and should be validated with everything else.
include_errors_from seems like a reasonable solution but maybe that should be in the wiki or in the docs somewhere.
-
Add Document.human_name in Rails Compatibility
3 comments Created about 1 month ago by sethladdTo conform closer to Rails, please add Document.human_name. This is expected when, among other things, the Mongo Document object is used inside Rails forms (especially Formtastic)
As you have a rails_compatibility/document.rb, I hope this is not too unreasonable of a request :)
Thanks!
Comments
See http://github.com/sethladd/mongomapper/tree/human-name-support for solution and tests
jnunemaker
Mon Nov 16 21:43:34 -0800 2009
| link
Added.
-
Set is not a natively supported type. That is, mongo_mapper does not ship with support for to_mongo and from_mongo for Set.
Comments
See http://github.com/sethladd/mongomapper for fix and tests
jnunemaker
Mon Nov 16 21:43:40 -0800 2009
| link
Added.
-
can save(false) mimic AR and save without calling the validations?
Comments
jnunemaker
Mon Nov 16 21:43:47 -0800 2009
| link
added.
-
Hello,
Having removed Github as a gem source, I went to install mongomapper and hit some issues with dependencies that were only hosted on Github. For example, http://gemcutter.org/gems/mongodb-mongo
It might be worth looking into to get everything over to Gemcutter for a smoother installation process.
Comments
jnunemaker
Fri Nov 06 16:47:38 -0800 2009
| link
All gem dependencies are on gemcutter. Did you install mongo_mapper or mongomapper? Without the underscore is the old version of the gem. The underscored one uses jnunemaker-validatable and mongo which are both on gemcutter.
Interesting! Thanks for the tip. I just checked and I guess I should have read the documentation completely...
jnunemaker
Sun Nov 08 09:56:50 -0800 2009
| link
No problem.
-
I'm not sure if this is intentional or if it's something I should be calling myself, but ensure_indexes! never seems to get called leaving the db with no indexes.
Comments
jnunemaker
Tue Nov 03 16:45:17 -0800 2009
| link
You have to call it yourself. You also have to make sure your models are loaded so it knows what indexes to actually create. You can read more here: http://groups.google.com/group/mongomapper/browse_thread/thread/2bebc5bdc4bb54a7
-
Embedded documents don't always instantiate with correct _type
1 comment Created about 1 month ago by jnunemakerComments
jnunemaker
Tue Nov 17 19:27:19 -0800 2009
| link
Embedded documents as keys now work with single collection inheritance. Closed by b847c38.
-
When calling "delete_all" on a model, a TCPSocket-object is returned. I would expect the collection of removed objects to be returned, just as "destroy_all" does. Is this on purpose?
Tested with:
- Rails 2.3.4 - MongoDB 1.0.1 (OS X, 32 bit) - MongoMapper 0.4.2To replicate:
- Create a class like this:
class Foo; include MongoMapper::Document; end
- On the Rails console: command "Foo.delete_all" returns: #<TCPSocket:0x12fad04>
Comments
jnunemaker
Sun Nov 01 14:09:32 -0800 2009
| link
delete_all is the run it and forget it version of destroy all so no it won't return the deleted records. destroy_all finds all the records and destroys them, delete all just sends the delete command and goes on about its business.
The thing is, I'm using an external gem that seeds the database with dummy data. It works like a charm with MongoDB (and MongoMapper), but it relies on "delete_all" to return the number of deleted objects (not the collection, my bad), so it can show how many objects were cleared from the DB before seeding the new data. This is what ActiveRecord returns from "delete_all".
So my actual question is (and then I'll shut up about it ;-)): is returning a TCPSocket a design decision of MongoMapper, or is it just not possible to do anything else with "delete_all" when using MongoDB (which uses TCP?)
jnunemaker
Mon Nov 02 07:28:28 -0800 2009
| link
Not a design decision, just what gets returned when you call remove on a collection in the ruby driver. The only way to return the number would be to do a count first and then a remove. Not sure that it matters in MM or not. Maybe for your project just do a count first and then a remove with the same options.
-
Hey,
this project is really cool, but one thing, is possible merge jnunemaker-validatable in mongomapper?
Then (i think will not be simple) is possible remove activesupport dependencies? This because many of us don't use mongomapper only with rails but also for sinatra or merb and merb for example have their active-support.
Comments
jnunemaker
Thu Oct 29 16:31:50 -0700 2009
| link
Nope it won't be possible by simply doing that. MM and validatable both use AS right now and probably always will. You can use AS just fine with sinatra. I'm not overly concerned with Merb support as it is dead. I might circle back around and see if I can remove the AS dependency but it won't be a simple switch.
Lipsiasoft
Fri Oct 30 01:53:32 -0700 2009
| link
And is possible merge MM and validatable?
jnunemaker
Sat Oct 31 06:13:44 -0700 2009
| link
Of course it is possible but it doesn't make any sense to do so. Validatable can be used on its own by other projects as is and merging it would remove that functionality.
-
Example:
BlogPost.all(:published_at => {:$lte => Time.zone.now})
=> MONGODB db.items.find({:type=>"BlogPost", :published_at=>{:type=>"BlogPost", :$lte=>Mon, 26 Oct 2009 18:24:33 EDT -04:00}})Note the :_type => 'BlogPost' is being added to the :published_at hash as well. I've fixed this, and pushed it to orderedlist/mongomapper.
Comments
jnunemaker
Wed Oct 28 10:42:18 -0700 2009
| link
Pulled and pushed. Will release gem soon.
-
Currently, if you do:
@document['not-here'] # you will get NoMethodError: undefined method `get' for nil:NilClassA more user friendly error message would help. (This bit me, actually, that's why I fixed it). My suggestion is here:
http://github.com/djsun/mongomapper/commit/dc136dbf5ec380abca8dfd8f5e5f5b0decce0789Comments
jnunemaker
Wed Oct 28 11:02:35 -0700 2009
| link
Friendly key not found exception. (initially by djsun) Closed by 6727fad.
-
Simple require 'mongo_mapper' raises exception on active_support constant issue
2 comments Created 2 months ago by natewareRuby 1.9.1 p243, Rails 2.3.4
Comments
One-line patch: http://gist.github.com/216136
jnunemaker
Thu Oct 22 21:12:34 -0700 2009
| link
Fixed.
-
Comments
jnunemaker
Thu Oct 22 21:13:20 -0700 2009
| link
Should MM raise an exception or should it just be an app level validation? In our app we are just doing validations.
jnunemaker
Tue Nov 17 19:40:34 -0800 2009
| link
Closing unless someone comes up with an idea.
-
for example, you can't define a :key called "attributes"
Comments
jnunemaker
Thu Oct 22 21:15:00 -0700 2009
| link
Basically any instance method in doc or embedded doc would be reserved. Any suggestions on implementation or is this more of a keep track of for when MM is ready for awesome documentation.
jnunemaker
Tue Nov 17 19:40:06 -0800 2009
| link
Closing unless someone else has an idea for implementation.
-
find_every should use _type in criteria if present
5 comments Created 2 months ago by shreeveSee title.
Comments
change to document.rb
def find_every(options) criteria, options = FinderOptions.new(options).to_a criteria.update(:_type => self.to_s) if self.keys.has_key?('_type') collection.find(criteria, options).to_a.map do |doc| begin _type = doc['_type'] if doc.respond_to?('_type') klass = _type.is_a?(String) ? _type.constantize : self klass.new(doc) rescue NameError new(doc) end end endAlso, we modified the begin clause to reduce needless exception throwing
Also, we're using ":_type, Array" to be able to support multiple inheritance. In this way, we can have a parent class called Person and inherited classes such as Patient and Physician, where a given person may be both a patient and a physician.
jnunemaker
Thu Oct 22 21:16:44 -0700 2009
| link
Hmm, not sure about the array but I just added support for _type in criteria in all queries. I pass the model to the FinderOptions and then determine if it should be added there so it happens everywhere instead of just in find_every.
-
All tests doesn't works like show by my integrity instance.
http://integrity.shingara.fr/mongomapper/commits/66424ec633bcc81076c40788828529ef44212192
I fix this test in my branch fix_test (http://github.com/shingara/mongomapper/commits/fix_test)
Comments
jnunemaker
Thu Oct 22 23:20:48 -0700 2009
| link
All tests are passing now.
-
Per the mongo recommendation, http://www.mongodb.org/display/DOCS/Queries+and+Cursors, finder's first method should use mongodb's findOne method.
Comments
jnunemaker
Thu Oct 22 23:18:50 -0700 2009
| link
Refactored most of the places that touch the database to be more consistent. Everything now takes options and collection.find_one is used in places where only one document is being found instead of find with a limit. Closed by 4684a6f.
compressed
Tue Oct 27 04:15:23 -0700 2009
| link
Awesome thanks John!
-
class Model include MongoMapper::Document many :widgets, :order => 'widget_size' endComments
jnunemaker
Wed Oct 28 13:31:45 -0700 2009
| link
Many Document associations can now have default query options/critiera. Closed by e41afd8.
-
ActiveRecord provides us with
attr_accessibleto ensure that certain attributes aren't overridden by mass-assignment. As near as I can tell, MongoMapper doesn't currently offer such a feature.Comments
jnunemaker
Thu Oct 15 20:30:28 -0700 2009
| link
Yeah, I had a ticket and closed it. I currently always use attr_accessible or attr_protected with AR but I find them a pain. The only reason we need them is because of the web which makes me think they are more of a controller issue than model issue.
Ryan Bates has done some work on this (http://github.com/ryanb/trusted-params). I can't say I liked his solution completely, but I think it is a step in the right direction. I'd be willing to put something in MM that allows determining which params are good to pass onto MM for convenience but I don't think I want anything directly in the model for this.
Feel free to continue discussion, but I'm closing the ticket unless I feel convinced otherwise.
I'm on the fence about
attr_accessibleas well, but what I'm concerned about is some user throwing in arbitrary data during a save or update. This may be a strength of the DB, and it does allow for some cool possibilities with MM, but the potential for abuse is kind of large, especially on applications like a wiki, or blog comments.Thoughts?
jnunemaker
Thu Oct 15 20:58:11 -0700 2009
| link
That was my first reaction. Then I realized it is no greater threat than stuffing a ton of stuff in a text column in mysql. Whether you use mysql or mongo, someone can shove crap in your database, even if you have attr_accessible.
I think the most basic level would just to reject any params in the controller that aren't in a trusted list. From there the rules could be different for every app. Initially I definitely thought my current stance was heresy but I'm kind of ok with it now.
I have some strong criticisms of Rails' attr_accessible that I wrote up here:
http://djwonk.com/blog/2008/05/23/improving-attr_accessible/I'm also working on sinatra_resource which adds a "resource" level to your API application. It makes it clean to protect your resources without gunking up your models:
http://github.com/djsun/sinatra_resourceFor an example of what a resource looks like, see:
http://github.com/djsun/sinatra_resource/blob/master/examples/datacatalog/resources/sources.rb
-
:dependent should not derefence the class until .destroy is called
2 comments Created 2 months ago by dcu>> class Thing; include MongoMapper::Document; key :do_not_exist_yet_id, String; belongs_to :do_not_exist_yet, :dependent => :destroy; end => Thing >> Thing.create SystemStackError: stack level too deep from /usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.5.4/bin/../lib/mongo_mapper/dirty.rb:57:in `initialize_without_dirty' from /usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.5.4/bin/../lib/mongo_mapper/dirty.rb:57:in `initialize' from /usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.5.4/bin/../lib/mongo_mapper/document.rb:117:in `new' from /usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.5.4/bin/../lib/mongo_mapper/document.rb:117:in `create' from /usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.5.4/bin/../lib/mongo_mapper/document.rb:116:in `each' from /usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.5.4/bin/../lib/mongo_mapper/document.rb:116:in `create' from (irb):8Comments
http://github.com/dcu/mongomapper/tree/fix-dependent fixes this issue
>> class Thing; include MongoMapper::Document; key :do_not_exist_yet_id, String; belongs_to :do_not_exist_yet, :dependent => :destroy; end => Thing >> Thing.create => # >> Thing.create.destroy => # >>
jnunemaker
Fri Oct 16 06:13:07 -0700 2009
| link
Merge branch 'fix-dependent' of git://github.com/dcu/mongomapper into dcu/fix-dependent. Closed by 01759b4.
-
>> class Thing; include MongoMapper::Document; end => Thing >> a = Thing.new => # >> b = Thing.new => # >> a[:foo] = nil => nil >> b.save => true >> b => #
Comments
http://github.com/dcu/mongomapper/tree/schema-free fixes this issue
-
ActiveModel (which will provide support for various ORMs) is deprecating the @model.errors.on(:method) convention in favor of @model.errors[:method]
perhaps mm should follow suit?
Comments
jnunemaker
Sun Oct 11 18:07:37 -0700 2009
| link
MM already supports this. Validatable was updated recently to alias [] to on.
activestylus
Sun Oct 11 18:27:01 -0700 2009
| link
Upgrading in 3..2..
-
Documents seem to be reporting .changed? == true even after they are just loaded. This does not seem like the expected behaviour.
This toy script demonstrates the problem (I can't get the tests to run)
require 'rubygems'
require 'mongo_mapper'MongoMapper.database = 'volatile_test'
class Log
include MongoMapper::Document key :text, String endLog.create :text => "HELLO"
l = Log.first
puts "are records dirty by default? #{l.changed?}"Comments
jnunemaker
Sun Oct 11 18:06:58 -0700 2009
| link
Looking into this. I know why.
jnunemaker
Sun Oct 11 18:22:16 -0700 2009
| link
Documents loaded from database no longer are marked dirty. Closed by 897f17b.
-
Time keys set unexpectedly as if they were auto timestamp fields
2 comments Created 2 months ago by djsunI'm using MongoMapper 0.5.2. I have several Time fields in my application that are getting set to Time.now on creation. (Of course, I'm not talking about the auto timestamps)
I wonder if this could be something happening at the MongoMapper or Mongo Ruby Driver levels. I'm not sure, this is just a hunch because I haven't isolated the problem yet.
Comments
jnunemaker
Sun Oct 11 12:21:30 -0700 2009
| link
Time.to_mongo now returns nil if value is nil or empty string. Closed by b50a1f7.
-
mongo_mapper > 0.4 (confirmed with 0.5) crashes under Ruby 1.9
1 comment Created 2 months ago by saadiqUnder Ruby 1.9 the "include MongoMapper::Finders" on line 7 of mongomapper/lib/mongo_mapper/associations/many_documents_proxy.rb crashes with the following error. To reproduce, go to the console and type "require 'mongo_mapper'".
/opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:105:in `rescue in const_missing': uninitialized constant MongoMapper::Associations::ManyDocumentsProxy::MongoMapper (NameError) from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:94:in `const_missing' from /Users/saadiq/dev/mongomapper/lib/mongo_mapper/associations/many_documents_proxy.rb:7:in `<class:ManyDocumentsProxy>' from /Users/saadiq/dev/mongomapper/lib/mongo_mapper/associations/many_documents_proxy.rb:3:in `<module:Associations>' from /Users/saadiq/dev/mongomapper/lib/mongo_mapper/associations/many_documents_proxy.rb:2:in `<module:MongoMapper>' from /Users/saadiq/dev/mongomapper/lib/mongo_mapper/associations/many_documents_proxy.rb:1:in `<top (required)>' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:in `require' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:in `block in require' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:521:in `new_constants_in' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:in `require' from /Users/saadiq/dev/mongomapper/lib/mongo_mapper.rb:75:in `<top (required)>' from /Users/saadiq/dev/mongomapper/test/test_helper.rb:15:in `require' from /Users/saadiq/dev/mongomapper/test/test_helper.rb:15:in `<top (required)>' from /Users/saadiq/dev/mongomapper/test/functional/associations/test_belongs_to_polymorphic_proxy.rb:1:in `require' from /Users/saadiq/dev/mongomapper/test/functional/associations/test_belongs_to_polymorphic_proxy.rb:1:in `<top (required)>' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `block in <main>' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `<main>' rake aborted!Comments
jnunemaker
Thu Oct 08 18:07:16 -0700 2009
| link
Nothing against ruby 1.9 but i'm not worried about it right now at all. If someone else wants to pioneer that front until I have time feel free. I'll create a new ticket that is ruby 1.9 support.
-
When using Rails' fancy partial rending, Action View doesn't think that a mongo association is an Array.
When I use:
<%= render @list.items %>I get:
Missing template arrays/_array.erb in view path app/viewsInternally, Action View uses the case comparison operator to compare if the argument is an array (
Array === arg), which apparently returns false for an association:>> Array === [] => true >> Array === List.first.items => falseComments
jnunemaker
Sun Dec 13 11:36:00 -0800 2009
| link
Added === for Association::Proxy so rails fancy partial rendering should work. Closed by a9a9428.
-
When building a basic has many like
class User
has_many :memberships endclass Membership
belongs_to :user endwhen you query User.first.memberships in ruby 1.9, I get a stack level too deep problem.
Comments
jnunemaker
Thu Oct 08 18:08:09 -0700 2009
| link
Nothing against ruby 1.9 but i'm not worried about it right now at all. If someone else wants to pioneer that front until I have time feel free. I'll create a new ticket that is ruby 1.9 support.
-
update_attributes bombs on EmbeddedDocuments
2 comments Created 2 months ago by jonathanI'm using inherited_resources in a rails app with mongo mapper. The update action on a document with a many association dies.
Processing CandidatesController#update (for 127.0.0.1 at 2009-10-04 19:04:44) [PUT]
Parameters: {"commit"=>"Save →", "id"=>"4ac7a91de23cde111f001002", "candidate"=>{"notes"=>"here is some text for a note", "phones"=>{"number"=>"555-555-5555", "type"=>"Mobile"}, "alias"=>"huskies"}}NoMethodError (undefined method
each_pair' for ["number", "555-555-5555"]:Array):<br/> mongomapper (0.4.1) lib/mongomapper/embedded_document.rb:209:inattributes=' mongomapper (0.4.1) lib/mongomapper/embedded_document.rb:186:ininitialize' mongomapper (0.4.1) lib/mongomapper/associations/many_embedded_proxy.rb:46:innew' mongomapper (0.4.1) lib/mongomapper/associations/many_embedded_proxy.rb:46:infind_target' mongomapper (0.4.1) lib/mongomapper/associations/many_embedded_proxy.rb:45:inmap' mongomapper (0.4.1) lib/mongomapper/associations/many_embedded_proxy.rb:45:infind_target' mongomapper (0.4.1) lib/mongomapper/associations/proxy.rb:48:inload_target' mongomapper (0.4.1) lib/mongomapper/associations/proxy.rb:38:inmethod_missing' mongomapper (0.4.1) lib/mongomapper/embedded_document.rb:251:into_mongo' mongomapper (0.4.1) lib/mongomapper/embedded_document.rb:249:ineach' mongomapper (0.4.1) lib/mongomapper/embedded_document.rb:249:into_mongo' mongomapper (0.4.1) lib/mongomapper/document.rb:328:insave_to_collection' mongomapper (0.4.1) lib/mongomapper/document.rb:323:inupdate_without_callbacks' mongomapper (0.4.1) lib/mongomapper/callbacks.rb:49:inupdate' mongomapper (0.4.1) lib/mongomapper/document.rb:307:increate_or_update_without_callbacks' mongomapper (0.4.1) lib/mongomapper/callbacks.rb:25:increate_or_update' mongomapper (0.4.1) lib/mongomapper/document.rb:290:insave_without_validation' mongomapper (0.4.1) lib/mongomapper/save_with_validation.rb:12:insave' mongomapper (0.4.1) lib/mongomapper/embedded_document.rb:305:inupdate_attributes' app/controllers/candidates_controller.rb:63:inupdate' /Library/Ruby/Gems/1.8/gems/josevalim-inherited_resources-0.9.1/lib/inherited_resources/legacy/respond_to.rb:101:incall' /Library/Ruby/Gems/1.8/gems/josevalim-inherited_resources-0.9.1/lib/inherited_resources/legacy/respond_to.rb:101:inretrieve_response_from_mimes' /Library/Ruby/Gems/1.8/gems/josevalim-inherited_resources-0.9.1/lib/inherited_resources/legacy/respond_to.rb:56:inrespond_to' app/controllers/candidates_controller.rb:62:in `update'Comments
You may want to try "fields_for :phones, :index => nil" which will wrap each phone in an array.
jnunemaker
Sun Oct 04 19:11:43 -0700 2009
| link
Post this to the google group instead of here so we can work through it easier and figure out if it is a bug or not.
-
A key with '' as a default value comes back as nil, not ''
4 comments Created 2 months ago by djsunTest revealing the problem here:
http://github.com/djsun/mongomapper/tree/problematic-empty-string-default
Comments
jnunemaker
Sun Oct 04 19:12:32 -0700 2009
| link
I am aware the a blank string is converted to nil. It was a choice. What is the use case for defaulting to a blank string?
To me, the argument goes like this: be as Ruby-like as possible. Ruby treats "" and nil differently. Why go against the grain?
With an array, do you consider [] and nil to be identical too? What about a hash: {} is the same as nil?
jnunemaker
Mon Oct 05 12:56:11 -0700 2009
| link
I can't remember my initial reason. Just changed it so empty string will be empty string.
-
This is the current version (0.4.1):
http://github.com/jnunemaker/mongomapper/blob/master/test/functional/associations/test_belongs_to_proxy.rbHere is my gist that illustrates several lines are false positives:
http://gist.github.com/201533
Comments
jnunemaker
Sun Oct 04 11:30:10 -0700 2009
| link
Yep, I'm aware and it is on my list of things to fix. Thanks for putting it here too.
jnunemaker
Sun Oct 11 07:03:32 -0700 2009
| link
Implemented nil? and inspect methods on proxy. Closed by 1194b72. (djsun)
-
Save/Create raise errors when working in Rails
6 comments Created 3 months ago by tpitaleThere seems to be a collision with ActiveRecord when using save on a new instance of a class which includes MongoMapper::Document. "NoMethodError: private method `save' called for #<RequestStatistic:0x1034a1e70>" Calling #update_attributes without any params saves the object. Using create also raises the same error.
Comments
jnunemaker
Wed Sep 30 20:44:14 -0700 2009
| link
Can you give more details, perhaps some example code? This is not much to go on. Thanks.
I've got a Rails 2.3.4 application. Pretty standard fare. I've added a mongomapper class that looks like this: http://gist.github.com/198724
If I try and do Statistic.create(:format => :html, :ip => '127.0.0.1', :path => '/') I get this (from script/console): http://gist.github.com/198727 The same error occurs with a different trace if I try Statistic.new.create().
jnunemaker
Wed Sep 30 21:19:08 -0700 2009
| link
That is a statistic model. Are you inheriting to make the RequestStatistic model or where is that coming into play?
No, sorry, RequestStatistic should just read Statistic. Typo.
jnunemaker
Sat Oct 03 19:37:17 -0700 2009
| link
Really no idea what is going on. I'm using MM with Rails 2.3.4 and not having any problems. I guess take it up at the google group until we know exactly why that is happening and can create a ticket for it.
-
Make methods like attribute_name_changed? and attribute_name_was
Comments
jnunemaker
Wed Sep 30 20:47:02 -0700 2009
| link
Definitely would like to get this in. I'll take a look at how rails does it and see what we can get going.
jnunemaker
Thu Oct 08 20:06:59 -0700 2009
| link
Added dirty attributes for documents. Closed by 969eccf.
-
Hi,
Documents that inherit from another document don't inherit the parent's class associations.
Example :
class Message include MongoMapper::Document key :body, String key :position, Integer key :_type, String key :room_id, String belongs_to :room end class Enter < Message; end class Exit < Message; end class Chat < Message; endEnter, Exit and Chat should have "belongs_to :room" as association too (like his superclass Message).
I made a patch for this issue :http://github.com/yeastymobs/mongomapper/commit/31052613fbdaba769294d0e46e1629d31e49528e
Comments
jnunemaker
Wed Sep 30 20:46:11 -0700 2009
| link
Ah. Good catch. I'll take a look at the patch soon.
jnunemaker
Wed Oct 07 19:42:57 -0700 2009
| link
This is fixed in 0.4 or 0.5
-
This would be useful to keep logic in the most relevant place, especially when the document is embedded in multiple models.
I don't know how hard this would be to implement. I looked into it a bit, but I don't know how to access the parent of the embedded document. Is this something you are interested in?
Comments
I think it'd be great if mongomapper supported callbacks on embedded documents, +1.
The Hashrocket fork of mongomapper allows embedded documents to access their parent document but it doesn't support callbacks on embedded documents...yet.It looks like andrewtimberlake's branch just added before_save functionality.
I just added complete callback support for embedded docs in my fork:
http://github.com/zef/mongomapperI'll make a pull request soon.
jnunemaker
Wed Sep 30 20:45:28 -0700 2009
| link
Awesome! I'll try to pull in the hashrocket fork and take a look at yours soon (zef).
the fork doesn't works now.
There are some plan to implement it ?
I've been meaning to update it to work with the current version.
Are there any thoughts you have about this John?
For me the callback in embedded document is the must important features needed.
MongoId has it :(
jnunemaker
Mon Nov 16 21:46:53 -0800 2009
| link
Then use mongoid or patch away. I haven't found a clean solution from any of the submissions and don't currently need it. If I don't need it it is hard for me to champion a solution as I don't know the best way to do it.
jnunemaker
Sun Dec 20 11:28:49 -0800 2009
| link
Created a ticket that explains how I'd like to see this done #129. Will work on it at some point. Closing this as now it is a duplicate.
-
Document#find([an_id]) should return an array
Comments
jnunemaker
Wed Sep 30 20:44:42 -0700 2009
| link
Yeah, this sucks. I'm aware of it. I'll fix this when I do some of the other find changes.
jnunemaker
Wed Oct 07 20:04:09 -0700 2009
| link
Finding an array of one id now returns an array instead of one document. Closed by 86172b8.
-
Given:
config.gem 'jnunemaker-mongomapper', :lib => 'mongomapper'Rails appears to be unsatisfied unless
require 'mongomapper'is somewhere, I assume because of autoloading -- Rails expects that the constant "MongoMapper" will map to a file called mongo_mapper.rb. Solution is to add a file to lib calledmongo_mapper.rbwith:require 'mongomapper'Comments
jnunemaker
Mon Sep 21 21:12:13 -0700 2009
| link
Yeah, I should have started with mongo_mapper from the beginning. I'll probably change this soon.
jnunemaker
Wed Oct 07 19:43:22 -0700 2009
| link
Fixed. Changed name to mongo_mapper in 0.5 which follows convention.
-
I added a way to extend has_many associations using a block or an :extend option. Extending belongs_to should work as well I believe, although I haven't tested that as I can't really think of a use case for it. Anyway I made a branch for it here, so you can check it out. If you like it, I should probably send you a patch as I stupidly pulled in changes from another fork into master thinking I'd use them before I made the branch, so it might be difficult to merge ;)
Comments
jnunemaker
Mon Sep 21 21:09:05 -0700 2009
| link
Cool, I'll take a look and either pull it in or give you my thoughts.
I applied mcmires changes against the current head here:
http://github.com/runeb/mongomapper/commit/78a20494e0c6bea89638b1348afca732a647007e
jnunemaker
Tue Oct 20 19:30:00 -0700 2009
| link
Thanks runeb.
jnunemaker
Wed Oct 28 11:53:01 -0700 2009
| link
Pulled and pushed. Will release gem soon.
-
Here's the backtrace:
Status: 500 Internal Server Error stack level too deep /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/util/byte_buffer.rb:65:in `put_array' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/util/byte_buffer.rb:72:in `put_int' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/util/bson.rb:422:in `serialize_number_element' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/util/bson.rb:118:in `serialize_key_value' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/util/bson.rb:95:in `serialize' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/util/bson.rb:95:in `each' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/util/bson.rb:95:in `serialize' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/util/bson.rb:430:in `serialize_object_element' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/util/bson.rb:120:in `serialize_key_value' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/util/bson.rb:95:in `serialize' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/util/ordered_hash.rb:50:in `each' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/util/ordered_hash.rb:50:in `each' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/util/bson.rb:95:in `serialize' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/message/message.rb:62:in `write_doc' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/message/query_message.rb:67:in `initialize' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/cursor.rb:218:in `new' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/cursor.rb:218:in `send_query_if_needed' /usr/lib64/ruby/1.8/mutex_m.rb:67:in `synchronize' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/db.rb:534:in `_synchronize' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/cursor.rb:217:in `send_query_if_needed' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/cursor.rb:195:in `refill_via_get_more' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/cursor.rb:179:in `num_remaining' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/cursor.rb:50:in `more?' /usr/lib64/ruby/gems/1.8/gems/mongodb-mongo-0.11.1/lib/mongo/cursor.rb:116:in `to_a' /usr/lib64/ruby/gems/1.8/gems/mongomapper-0.3.3/lib/mongomapper/document.rb:174:in `find_every' /usr/lib64/ruby/gems/1.8/gems/mongomapper-0.3.3/lib/mongomapper/document.rb:179:in `find_first' /usr/lib64/ruby/gems/1.8/gems/mongomapper-0.3.3/lib/mongomapper/document.rb:52:in `first' /data/busk/releases/20090903194259/app/models/url.rb:15:in `generate_code' /data/busk/releases/20090903194259/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `send' /data/busk/releases/20090903194259/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `evaluate_method'Comments
jnunemaker
Thu Sep 03 14:59:10 -0700 2009
| link
This is better for the google group http://groups.google.com/group/mongomapper/. Closing here. I would check that you have the latest version of mongomapper. The mongo driver that shows up in your stack trace is 0.11.1 but the latest version of mongomapper requires 0.14 or something like that.
lucashungaro
Thu Sep 03 15:02:13 -0700 2009
| link
I forgot about the google group, sorry!
-
desired behavior? --> errors not populated until after valid? is called
2 comments Created 3 months ago by djsun(This is probably due to the underlying Validatable library.)
Here is an example from the project I'm working on:
r = Rating.new r.errors => #<Validatable::Errors:0x102392c10> r.valid? => false r.errors => #<Validatable::Errors:0x102392c10 @errors={:kind=>["is invalid"]}>Comments
Ok, now that I've talked this out with a few people I like this behavior after all.
jnunemaker
Thu Sep 03 14:59:30 -0700 2009
| link
Yes, that is the desired behavior.
-
Log stuff like collection, query and query time
Comments
In mongo-ruby-driver, a logging support is insert on master branch
Lipsiasoft
Fri Oct 02 16:11:11 -0700 2009
| link
it's very important without them is impossible to use in production env
jnunemaker
Wed Oct 07 19:15:05 -0700 2009
| link
Added MongoMapper.logger method which logs to the mongo ruby driver connection logger instance. Closed by 0b09d1e.
-
object.send seems to be broke with new release
1 comment Created 4 months ago by monkeyhelperPage isa MongoMapper::Document
page_opts = { :attribute1 => 'value1', :attribute2 => 'attribute2' } p = Page.find(:first) page_opts.each do |attribute, value| p.send attribute, value endCode used to work under previous versions of mongomapper but no object.send seems broke.
Comments
jnunemaker
Mon Aug 31 18:12:36 -0700 2009
| link
You have to send "#{attribute}=", value to set the value.
-
timestamps! doesn't work for embedded documents
2 comments Created 4 months ago by monkeyhelpertimestamps! is an unknown method for : MongoMapper::EmbeddedDocument
Comments
jnunemaker
Mon Aug 31 18:08:18 -0700 2009
| link
This is intentional. Embedded docs are not aware of when they are being saved so there is no way to set the timestamps automatically at this point.
jnunemaker
Mon Aug 31 18:13:58 -0700 2009
| link
Closing. This will work when embedded documents become aware of parent document save. No time frame on that now.
-
Comments
jnunemaker
Wed Oct 07 20:09:56 -0700 2009
| link
this works now, just an out of date ticket
-
Comments
jnunemaker
Wed Oct 07 20:11:19 -0700 2009
| link
Should work fine now. Was fixed and forgot to close.
-
Comments
jnunemaker
Sat Aug 29 14:06:58 -0700 2009
| link
Fixed in master.
-
I think now that dynamic finders are in 0.3.3, it would be very natural to have a dynamic finder for many associations as well.
magazine.subscriptions.find_by_isbn(isbn)would be equivalent to:
Subscription.first(:conditions => { :magazine_id => magazine.id, :isbn_url => isbn) })Comments
jnunemaker
Wed Oct 07 19:15:45 -0700 2009
| link
Added in 0.5
-
Comments
malkomalko
Tue Aug 18 10:28:50 -0700 2009
| link
looks like dcu has implemented this no?
jnunemaker
Fri Aug 21 18:52:39 -0700 2009
| link
yes he has i just need to review and pull in
jnunemaker
Sat Aug 29 14:13:31 -0700 2009
| link
Pulled in and released in 0.3.4.
-
Remove all magic keys and force explicit declaration of them
1 comment Created 4 months ago by jnunemaker_ type is the first that comes to mind. There may be others. This will fix issues with polymorphic models and load order and will also make it easier to address _type assignment when not scoped to association.
Comments
jnunemaker
Sun Aug 16 14:34:33 -0700 2009
| link
Removed all magic keys. You now have to declare belongs_to and polymorphic keys in your model. They do not happen automatically behind the scenes. losed by 2610cc3.
I felt like too much was happening behind the scenes. It has caused some confusion for people starting out. Now, you have to declare the keys and the good part is then you know they are there (as they aren't hiding).
-
You can use longs currently with dynamic keys though since the driver supports them. I have never used them really so I'm not the person to implement the typecasting of Longs to actually make them a native mongomapper type.
Comments
jnunemaker
Sun Aug 16 11:57:45 -0700 2009
| link
Added test for using Integer with long ints. losed by fc4151c.
-
Comments
jnunemaker
Sun Aug 16 08:39:05 -0700 2009
| link
Bumped the mongo ruby driver version to 0.11.1. losed by 121971e.
-
attributes= should work with anything that comes out of the database
1 comment Created 4 months ago by jnunemakerRight now if you there is a key in the database you don't have in your model, it throws an error.
http://groups.google.com/group/mongomapper/browse_thread/thread/1868dee9eb24b200?hl=en
Comments
jnunemaker
Sun Aug 16 08:46:41 -0700 2009
| link
Added test for loading documents from the database that have keys not defined in document. losed by 6990292.
-
find returns nil, find! raises an exception
2 comments Created 4 months ago by jnunemakerThis is a bit more consistent with find_by... and find_by...! and such. Find will always return nil if document not found by id and find! will work like find currently does raising a DocumentNotFound exception.
Comments
-
validates_uniqueness should have support for :scope option
Comments
jnunemaker
Thu Aug 13 10:31:55 -0700 2009
| link
good idea.
jnunemaker
Sat Oct 03 20:50:35 -0700 2009
| link
Added in 0.4
-
update_attributes does not return false on failed save
5 comments Created 4 months ago by btomlinWhen obj.update_attributes fails to save (ie due to validation) the obj is returned instead of false. This causes validation messages not to work on updates in the rails view. For Example:
def update @note = Note.find(params[:id]) if @note.update_attributes(params[:note]) redirect_to @note else render 'edit' end endJust redirects if the validation fails instead of rendering 'edit' because the note object is returned.
irb example:
>> note.update_attributes(:title => '') => #<Note _id: bf8601aa4a7dd708000000eb, created_at: 2009-08-08 19:50:32 UTC, updated_at: 2009-08-08 20:25:44 UTC, title: , body: this is note 1, tags: []>Comments
jnunemaker
Thu Aug 13 10:32:24 -0700 2009
| link
good catch. i'll definitely fix this up.
I've done a patch that addresses this issue: http://github.com/durran/mongomapper/tree/update-attributes-validation-issue-50
jnunemaker
Fri Aug 14 17:19:41 -0700 2009
| link
Awesome. I'll take a look.
Very cool. I was planning on looking at it this weekend, but this solution looks good. All the other tests still pass except for one that didn't pass before the update. Cool.
jnunemaker
Fri Aug 14 19:05:07 -0700 2009
| link
Fixed in SHA: 4ea1814
-
Problem with additional keys in a child class
1 comment Created 4 months ago by nmerouzeIf I have a Message with a body and its child Enter with a key title that it's not in Message, I have an error when I retrieve all messages :
class Message include MongoMapper::Document key :body, String end class Enter < Message key :title, String end Enter.create(:body => "Body test", :title => "Title test") Message.all # It breaks because title= is undefined in MessageComments
jnunemaker
Sun Aug 16 11:38:28 -0700 2009
| link
This will not cause problems in 0.3.3 I believe.
-
I have Message, Enter and Exit inherit from it. If I create a Enter document, I have nothing in _type. But if I create it in the association array, it works :
>> Enter.create # It doesn't work >> r=Room.create >> r.messages << Enter.create # It works
Comments
jnunemaker
Sun Aug 16 11:51:53 -0700 2009
| link
The best way to fix this is to force people to declare the _type key instead of dynamically adding it through the association. I'll look into getting this going.
jnunemaker
Sat Aug 29 13:27:46 -0700 2009
| link
This is fixed in master. If _type key is defined and value is blank, it gets set during initialize.
-
Hi,
I have a model Message, Enter and Exit derived from it. I create one document for each, then I want all the Enter documents. But the result is wrong and I have all the documents but with the right _type (Enter for one, Exit for the other) :
>> r=Room.create >> r.messages = [Enter.create, Exit.create] >> Enter.all => [ #< Enter updated_at: Thu Aug 06 14:20:43 UTC 2009, _id: 4df37cd94a7ae6bb00000068, _type: Enter, created_at: Thu Aug 06 14:20:43 UTC 2009>, #< Enter updated_at: Thu Aug 06 14:28:06 UTC 2009, _id: 4df37cd94a7ae87600000068, _type: Exit, created_at: Thu Aug 06 14:28:06 UTC 2009>]But I just want the Enter documents.
NB : If I do Enter.create without passing it in the association I have nothing in _type, but I'm gonna create another issue for that.
Comments
jnunemaker
Fri Aug 14 17:07:37 -0700 2009
| link
Right now polymorphic stuff is only for assignment. If you want to do stuff like that you need to add the _type: 'Enter' condition. Thanks for pointing it out and making a ticket.
jnunemaker
Thu Oct 22 14:05:20 -0700 2009
| link
Models with _type key are no properly scoped when performing find and count. Closed by 32c454d.
-
Failing tests (including some intermittent failures)
4 comments Created 4 months ago by djsunIn order to get tests passing on my system, I had to change several tests to "should_eventually" (e.g. marking them as pending so they don't run).
http://github.com/djsun/mongomapper/commit/f15dfa9f18078e9ef6a5f49fd86de05b6bae9168
http://github.com/djsun/mongomapper/commit/cc486bef3365364a3531c3e8b8d0d7975e067a52
Intermittent failures are tricky. I ran test_many_polymorphic_proxy.rb test probably 20+ times to identify the ones above.
Comments
jnunemaker
Mon Aug 03 19:34:59 -0700 2009
| link
I believe this has to do with $natural ordering. Try downloading the mongodb nightly and then running the test suite.
I installed nightly build just now.
I did two different runs:
against the 'stable' version of mongomapper (installed via RubyGems). I got 10 failures:
http://gist.github.com/161293against your git repo. I got 4 failures:
http://gist.github.com/161299
It looks like you are knocking out the failing tests (6 better than the last gem release). However, there are still some failing tests that aren't solved by simply using the MongoDB nightly build.
I should have mentioned that the intermittent problems are still around even with the nightly build. (My above comment was just for one run each of each).
Here are the results after running each test suite 10 times. I list the number of failing tests
#1. 10, 10, 10, 10, 12, 12, 10, 10, 10, 10
#2. 4, 5, 4, 4, 3, 3, 4, 5, 3, 4
jnunemaker
Sun Aug 16 08:53:39 -0700 2009
| link
Pretty sure these are zapped.
-
Will be beautifull if is possible query like that
Account.find(:conditions => { :any => /full_text_search/i })Where ANY are All fields of the document
Then like others ticket:
Account.find(:conditions => "account_details.age > 10")Then I thinks is necessary a way for "shortcut" conditions, because in some cases hash will be very very very long so I think we can use the "where" clause of mongo with a direct string like:
Account.find("account_details.age > 16 OR orders.size > 10")Comments
jnunemaker
Fri Aug 14 19:11:32 -0700 2009
| link
If you need to do stuff like this I would just use $where. See the mongo docs for it. I don't really have any interest in writing a string to hash converter to make this stuff work.
-
Right now _id is default so you get the binary representation but what makes sense is a string representation of it.
Comments
jnunemaker
Sun Aug 02 21:12:22 -0700 2009
| link
Embedded documents now have id as well. Also to_json now includes id and excludes id by default. losed by 2634ff7.
-
find_by_id raises incorrect exception with invalid id
2 comments Created 5 months ago by jnunemakerIf invalid id provided, it should not raise DocumentNotFound.
Comments
Some discussion from the group list is here:
http://groups.google.com/group/mongomapper/browse_thread/thread/e8a8ecc0e2ecda8f
jnunemaker
Sun Aug 02 19:28:40 -0700 2009
| link
MongoID.mm_typecast now raises MongoMapper::IllegalID if id is illegal rather than DocumentNotFound. losed by 7ae274e.
-
It would be nice to have a BigDecimal key type.
Comments
jnunemaker
Sun Aug 02 21:14:04 -0700 2009
| link
MongoDB only supports Integer and Float native types. I have not worked with BigDecimal. Would it make sense to store as float in mongo and then cast as big decimal when accessing?
commondream
Sun Aug 02 22:09:13 -0700 2009
| link
I think it could make sense, but you could in theory also run into typical floating point conversion issues like this: http://yuiblog.com/blog/2009/03/10/when-you-cant-count-on-your-numbers/ .
I'm not totally sure what the best tactic is. Without a decimal type I don't think that there's any really great solution.
The only time I can think of that I've used BigDecimal is for currencies, so it could make sense to go with a type for that that is integer based and not worry about the rest. That was the issue I ran into the other night when I put this issue in. It could make sense to just say that users should use an integer and coerce them as they need in their applications.
jnunemaker
Sun Aug 16 11:43:25 -0700 2009
| link
I'd probably lean towards integer and coerce if I was dealing with money. Closing the ticket for now. If someone wants to patch I'd take a look but no guarantees.
-
I tried versions 0.2.0 and 0.3.1 of MongoMapper with versions 0.9, 0.10.0 and 0.10.1 of the MongoDB Ruby driver and got the same error every time:
/usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/util/bson.rb:77:in `serialize': wrong number of arguments (2 for 1) (ArgumentError)from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/util/bson.rb:77:in `serialize' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/message/message.rb:62:in `write_doc' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/message/query_message.rb:67:in `initialize' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/cursor.rb:215:in `new' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/cursor.rb:215:in `send_query_if_needed' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/cursor.rb:195:in `refill_via_get_more' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/cursor.rb:179:in `num_remaining' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/cursor.rb:56:in `next_object'Comments
arthurgeek
Tue Jul 28 16:25:39 -0700 2009
| link
I have the same problem.
lucashungaro
Thu Jul 30 00:20:31 -0700 2009
| link
Installing mongodb-mongo_ext solved the issue - maybe it should be added as a dependency.
jnunemaker
Fri Jul 31 11:42:43 -0700 2009
| link
Are you sure you have the latest version of the ext gem? You can either uninstall it or upgrade to latest.
lucashungaro
Fri Jul 31 12:04:27 -0700 2009
| link
Oh boy... :P
After further inspection I found that I had mongo_ext version 0.1.1 installed previously and totally forgot about it. So, when I first tried MongoMapper, the extensions were outdated and causing the issues.
Clarifying: MongoMapper works without mongo_ext or with the latest version (0.4.1). :)
Thanks John. Congrats on the great work done.
jnunemaker
Fri Jul 31 17:21:19 -0700 2009
| link
Closing this as it is not an issue anymore.
-
This is a query ticket really, it doesn't look like the db.collection.group method is coded up at the moment. Are there any thoughts about how it would be added in. I was thinking it could be :
Collection.group( :ns => "coll", :key => { :a => true, :b => true }, :cond => {:active => 1}, :reduce => 'function(''obj'',''prev'') { prev.csum += obj.c; },', :initial => {:csum => 0} )
Or is there another way this is/could be tackled ?
Comments
You can access the underlying mongodb adapted collection using the #collection class method @monkeyhelper. Until something nicer gets implemented with mongomapper. It takes (in order) an array of keys (to group by), a hash of the the initial values, a conditions hash, and the javascript function.
Not that I'm aware of. Somebody else feel free to correct me, though.
jnunemaker
Wed Oct 07 20:41:10 -0700 2009
| link
The new map reduce stuff will work for this. I'll wait to work on anything until that is all good to go.
-
It would be pretty handy to be able to specify capped collections.
From what I understand they do need to be created when first creating the collection and can't be added later (like indexes or keys). Perhaps adding an option to the database method in the document?
So this is more just a ticket for the feature and perhaps thoughts on the best way to implement...
Comments
jnunemaker
Wed Jul 22 19:17:23 -0700 2009
| link
Yeah, I haven't used them yet but that would be something I'd like to see in. Thanks for adding it. If you get any ideas or anyone else re:implementation go for it and let me know.
hey hunter,
remember that MongoMapper wraps the underlying Mongo ruby driver. You can do something like this in an initializer:
YourModelClass.database.create_collection(YourModelClass.collection_name, :capped => true, :size => 1024, :max => 12)
jnunemaker
Thu Oct 22 23:19:58 -0700 2009
| link
Thanks for pointing that out skippy. I should have mentioned that.
jnunemaker
Tue Nov 17 19:41:21 -0800 2009
| link
Closing. Recommending skippy's example for now. No need to support natively in MM right now.
-
Document does not persist its embedded document's set of embedded documents
5 comments Created 5 months ago by sandroshould "store embedded documents from the embedded document" do @document = Class.new do include MongoMapper::Document many :people end sparky = Pet.new(:name => "Sparky", :species => "Dog") meg = Person.new(:name => "Meg", :pets => [sparky]) doc = @document.new :people => [meg] doc.people.first.pets.first.should == sparky endComments
I made the test pass by merging embedded_association_attributes into the objects attributes within the has_many_embedded_proxy. Why doesn't #attributes always include the embedded_association_attributes?
Hello Sandro. I had the same problem yesterday - today I found Felipe's mongomapper fork at fcoury/mongomapper (http://github.com/fcoury/mongomapper/tree/master). It seems the issue is fixed in it's "master" branch - probably through changes in the "embedded_association_attributes" method (if I'm not mistaken). I hope this helps.
jnunemaker
Wed Jul 22 19:18:36 -0700 2009
| link
I'm planning on pull Felipe's in soon. Been swamped past few days.
Thanks for the replies. Take it easy, you're doing awesome work nunemaker.
jnunemaker
Mon Jul 27 07:57:38 -0700 2009
| link
Closing this as I'm pretty sure this is is fixed in master.
-
Suppose I have a Project which embeds people, and each person embeds images.
person = Person.new person.images << image project = Project.new project.people << person project.save Project.find(project.id).people.first.images.first.any? # falseI've created a gist for a failing association test: http://gist.github.com/150095
Comments
jnunemaker
Sun Jul 19 17:36:43 -0700 2009
| link
Have you tried this with master? I pushed some fixes but haven't released them as a gem yet.
Woah! super fast response time, awesome! I'm amazed at the amount of commits I just pulled down, I just created my repo earlier today, way to go! Problem solved.
Keep up the good work, MongoMapper is super fun.
jnunemaker
Sun Jul 19 19:28:24 -0700 2009
| link
Cool. I'm closing the ticket.
-
It appears that MongoDB doesn't support anything larger than 4-byte ints. The ruby driver raises an error suggesting the use of a Double.
Perhaps not a great deal that can be done but raising anyway.
Comments
jnunemaker
Mon Jul 27 07:54:46 -0700 2009
| link
So is there something I am suppose to do with this? Seems like more of a statement.
Oops, just me not paying enough attention when writing a ticket ;)
I guess the question is, can we add support for large ints? It seems the Integer key raises the mongo driver 4-bit int error. The typecast method in key.rb just seems to pass this on the Int so it may be the driver. I've not had time to dig further. Any thoughts?
jnunemaker
Fri Jul 31 17:22:42 -0700 2009
| link
I don't really know much on the subject. I'd hit up the mongodb mailing list about best way to store big ints and we can go from there.
jnunemaker
Sun Aug 16 11:47:43 -0700 2009
| link
Longs are now supported by the ruby driver. That with the combination of keys with no type means you could use longs now with mongomapper if you just do something like this:
class Foo include MongoMapper::Document key :somelongint end Foo.new.somelongint = 9223372036854775807 # or whateverAlso, this is kind of duplicate with ticket #55.
-
Use of :all or :in in find with array causes error
3 comments Created 5 months ago by monkeyhelperFor :
Page.all(:conditions => { 'entities.uri' => { '$all' => ['Blah'] }}).each do |page|
An error is raised :
RuntimeError ($all requires array):
/usr/lib/ruby/gems/1.8/gems/mongodb-mongo-0.9/lib/mongo/cursor.rb:68:innext_object' /usr/lib/ruby/gems/1.8/gems/mongodb-mongo-0.9/lib/mongo/cursor.rb:117:into_a' /usr/lib/ruby/gems/1.8/gems/jnunemaker-mongomapper-0.2.0/lib/mongomapper/document.rb:144:infind_every' /usr/lib/ruby/gems/1.8/gems/jnunemaker-mongomapper-0.2.0/lib/mongomapper/document.rb:48:inall'The same error occurs with $in too.
Comments
monkeyhelper
Mon Jul 13 01:44:20 -0700 2009
| link
It seems to generate the following via finder_options :
"$all"=>{"$in"=>["Blah"]}}
jnunemaker
Tue Jul 14 16:26:24 -0700 2009
| link
Ah suck. Yeah that is definitely a bug in FinderOptions
jnunemaker
Sun Jul 26 17:27:13 -0700 2009
| link
No longer defaulting Array in conditions to $in. Now only does it if another modifier starting with $ is not already present. losed by 8e81d88.
-
Allow for shortcuts on the fields that convert to mongo speak
6 comments Created 5 months ago by jnunemakerPerson.all :age.gt => 60 to translate to :age => {'$gt' => 60}Should also work for gt, gte, lt, lte, all, in, etc.
Comments
jnunemaker
Wed Oct 28 11:46:03 -0700 2009
| link
I like it for sure. I just haven't had time to implement or think about how to implement.
I've just implemented it in a branch of my fork. Let me know if you like the style or if it stinks.
jnunemaker
Thu Oct 29 10:57:08 -0700 2009
| link
Weird, thought I did.
-
Allow for condition auto-detection when finding
1 comment Created 5 months ago by jnunemakerI'd like to be able to do finds without passing :conditions. Just detect the conditions based on removing keys that we know are not related to conditions like select, fields, order, limit, offset, sort, etc.
Article.first('tags.name' => %w(foo bar))Comments
jnunemaker
Sat Oct 10 22:01:00 -0700 2009
| link
Implemented condition auto detection. Supports old-style :conditions hash as well. Closed by 763c3fc.
What use to be:
Foo.all(:conditions => {:bar => true})Can now be:
Foo.all(:bar => true) -
use of :class_name breaks association storage
1 comment Created 5 months ago by monkeyhelperUsing module namespaces and thus :class_name breaks document storage.
See namespaced version of test/test_associations.rb
rake test gives :
1) Failure: test: Many documents should store the association. (AssociationsTest) [/usr/lib/ruby/gems/1.8/gems/jnunemaker-matchy-0.4.0/lib/matchy/built_in/operator_expectations.rb:30:in
fail!' /usr/lib/ruby/gems/1.8/gems/jnunemaker-matchy-0.4.0/lib/matchy/built_in/operator_expectations.rb:20:in==' ./test/test_associations.rb:123:in__bind_1247168503_298757' /usr/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb:253:incall' /usr/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb:253:intest: Many documents should store the association. ' /usr/lib/ruby/gems/1.8/gems/mocha- 0.9.7/lib/mocha/integration/test_unit/gem_version_201_and_above.rb:20:inrun']: Expected 0 to == 1.Comments
jnunemaker
Fri Jul 10 16:12:06 -0700 2009
| link
Yep, that isn't added yet. There are already tickets for belongs_to http://github.com/jnunemaker/mongomapper/issues#issue/24 and many http://github.com/jnunemaker/mongomapper/issues#issue/28 so I'll close this one.
Associations are really basic right now, nothing like rails yet but they will be.
-
When performing a find with an array of values,there doesn't seem to be any way to do :
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-ConditionalOperator%3A%24all
Comments
jnunemaker
Fri Jul 10 16:10:20 -0700 2009
| link
I think all you need to do is this:
Article.find(:all, :conditions => {:tags => {'$all' => ['mongo', 'db']}})If that doesn't work, reopen the ticket or create a new one if you can't.
-
validates_uniqueness_of does not handle :case_sensitive
6 comments Created 5 months ago by daeltarComments
jnunemaker
Fri Jul 10 16:08:53 -0700 2009
| link
I don't think there is a way to query case sensitive in mongo. maybe with a regex but that might be really slow. what i've been doing is just downcasing stuff and comparing with downcase.
yes the only way is the regex at the moment. /#{attribute_value}/i
which does case insensitive matching.i have one question about validatable:
shouldn't we have error codes like the following :
MessageCodeFor = {
:unique => "attribute.duplicate.entry".freeze, :format => "attribute.format.invalid".freeze, :length => "attribute.length.invalid".freeze, :valid => "attribute.document.invalid".freeze, :logic => "attribute.logic.false".freeze, :accept => "attribute.not.accepted".freeze, :required => "attribute.not.present".freeze, :exclusion => "attribute.is.reserved".freeze, :inclusion => "attribute.is.out.of.list".freeze, :confirmation => "attribute.confirmation.failed".freeze, :match => "attribute.match.failed".freeze, :integer => "attribute.not.an.integer".freeze, :numeric => "attribute.not.a.number".freeze }These things can help I18n easier? I have a fork on validatable that fixes this issue. Fixed the tests for the same.
djspinmonkey
Thu Oct 29 12:40:20 -0700 2009
| link
You could also use a $where clause in the find() to call toLowerCase() on an attribute and compare it to a string. It'd still be a performance hit, but I think it might be better than the regex approach (though I haven't done any benchmarks yet).
djspinmonkey
Thu Oct 29 14:45:09 -0700 2009
| link
I've submitted a pull request for a fix using the approach described above.
jnunemaker
Sat Oct 31 21:38:34 -0700 2009
| link
Added case sensitive option to validates_uniqueness_of. (djspinmonkey) Closed by 0524bf5.
-
Then we don't have to do lots of queries to pull them out.
I'm thinking belongs_to :user would create two keys: :user_id and :user_reference.
- user_id would work just like it does now.
- user_id= would set user_id and user_reference.
- user would return db referenced object wrapped in new User instance (User.new(db referenced attributes).
- user= would set user_id and user_reference.
Something like that should work.
Comments
I had no idea what this issue meant or was in reference to until I spent some more time digging through the schema design documentation for MongoDB. For the illumination of anyone else looking at this issue, the information on DBRefs can be found here: http://www.mongodb.org/display/DOCS/DB+Ref+Specification
jnunemaker
Sat Oct 03 19:29:46 -0700 2009
| link
I did some reserach on DBRefs and they are just glorified foreign keys which means there is no point in using them. We'll stick with foreign keys for now.
-
Should be able to create, build, etc. on associations
3 comments Created 5 months ago by jnunemakerstuff like this should work:
mm = Project.create(:name => 'MongoMapper') mm.statuses.build(params[:status]) mm.statuses.create(params[:status]) mm.statuses << Status.new(:name => 'mm1') mm.statuses.push Status.new(:name => 'mm1')Comments
BrianTheCoder
Wed Jul 08 17:20:27 -0700 2009
| link
personally I like mm.statues.new(params[:status]) better than build, it seems more rubyish
jnunemaker
Fri Jul 10 16:07:43 -0700 2009
| link
I say we use new and then just alias build in the rails compatibility module.
jnunemaker
Sun Aug 02 19:28:40 -0700 2009
| link
Implemented build and create for many and many polymorphic documents. losed by 1351c65.
-
Should be able to find on associations and keep scoping
0 comments Created 5 months ago by jnunemakerstuff like this should work:
mm = Project.new(:name => 'MongoMapper') mm.statuses = [Status.new(:name => 'mm1'), Status.new(:name => 'mm2')] mm.save hm = Project.new(:name => 'HappyMapper') hm.statuses = [Status.new(:name => 'hm1'), Status.new(:name => 'hm2')] hm.save mm.statuses.find(:all).collect(&:name).should == ['mm1', 'mm2']Comments
-
Add :required option to belongs_to declaration
1 comment Created 5 months ago by jnunemakerThis will add :required => true to the key declaration inside belongs_to.
Comments
jnunemaker
Mon Jul 27 13:44:16 -0700 2009
| link
Don't like this idea anymore.
-
Allow changing class for belongs_to association
1 comment Created 5 months ago by jnunemakerSo you can have things like belongs_to :owner that maps to User class.
Comments
jnunemaker
Mon Jul 27 09:06:36 -0700 2009
| link
This works in master.
-
Finder methods currently sanitize the conditions hash and map an array to a Mongo $in condition. The count method with the same arguments does not do this.
Finder options might be too heavy for count. Should we make convert_conditions public so we can call it in the count case?
Comments
jnunemaker
Tue Jul 07 09:16:39 -0700 2009
| link
Yeah, I ran into this too. I'll come up with a solution and push it. I have some ideas.
jnunemaker
Tue Jul 07 09:48:29 -0700 2009
| link
Implemented more thorough use of converting find conditions and options to mongo criteria and options. losed by 6f161df.
-
Right now it bombs with nil.each because I assume that it is a hash.
Comments
jnunemaker
Tue Jul 07 09:55:51 -0700 2009
| link
EmbeddedDocument#attributes= no longer bombs when given nil. losed by d7c079e.
-
Try adding an error in one of them and it goes away after valid? is actually called. These are going to need to be moved into validatable instead of in mongomapper.
Comments
jnunemaker
Sun Jul 05 13:07:26 -0700 2009
| link
Fixed in 0.1.3 which should be out if not already.
-
Comments
jnunemaker
Tue Jul 07 11:20:11 -0700 2009
| link
Added validates_exclusion_of. losed by de02369.
-
Comments
jnunemaker
Tue Jul 07 11:20:11 -0700 2009
| link
Added validates_inclusion_of and fixed bug in validates_exclusion_of. losed by f710606.
-
Write now I just have a bunch of tests. I want to separate those that are unit from those that are more functional, such as hitting the database.
Comments
jnunemaker
Mon Jul 27 07:47:33 -0700 2009
| link
This is done for the most part as of last night (July 26, 2009).
-
find_all_by and find_by using method missing.
Comments
jnunemaker
Sun Aug 16 11:04:30 -0700 2009
| link
These are working in 0.3.3.
-
Basically validatable doesn't support the symbol to proc stuff. I'm adding the issue here because github won't let me add it on jnunemaker-validatable for some reason.
Comments
jnunemaker
Tue Jul 07 12:02:12 -0700 2009
| link
In the meantime you can share :if logic with procs. I did something like this:
PasswordRequired = Proc.new { |u| u.password_required? } validates_presence_of :password, :if => PasswordRequired validates_confirmation_of :password, :if => PasswordRequired, :allow_nil => true validates_length_of :password, :minimum => 6, :if => PasswordRequired, :allow_nil => true
jnunemaker
Mon Jul 27 07:53:45 -0700 2009
| link
This is fixed in 0.2.1 which should be out in the next few days.
-
Add validate, validate_on_create and validate_on_update callbacks
1 comment Created 6 months ago by jnunemakerComments
jnunemaker
Sun Jul 05 13:06:56 -0700 2009
| link
Fixed in 0.1.3 which should be out soon if not already.
-
Also, :unique => true shortcut. Probably a query will work best for this until I know for certain how unique indexes work in mongo.
Comments
jnunemaker
Tue Jul 07 10:36:48 -0700 2009
| link
added :unique key shortcut to add validates_uniqueness_of automatically. losed by 4f362ee.
-
Rename SubDocument to EmbeddedDocument as that makes more sense
1 comment Created 6 months ago by jnunemakerWhen I used sub document in the presentation I got blank looks, but when I changed my verbiage to embedded document it seemed to click for everyone, thus the change.
Comments
jnunemaker
Fri Jun 05 11:29:51 -0700 2009
| link
Renamed sub document to embedded document. losed by 29d0291.
-
Allow setting default values when defining keys
1 comment Created 7 months ago by jnunemakerSomething like this:
key :published, Boolean, :default => false
Comments
jnunemaker
Sun May 31 20:36:14 -0700 2009
| link
Allow setting default values for keys when defining them in a document. losed by 9fa8529.
-
I'd like to see this work with the same api as rails.
Comments
BrianTheCoder
Wed Jul 08 17:23:09 -0700 2009
| link
It might be nice to take a note from dm here so you could do something like
key :encrypted_password, :protected => true
jnunemaker
Fri Jul 10 16:07:18 -0700 2009
| link
love it
jnunemaker
Wed Oct 07 19:42:14 -0700 2009
| link
I'm thinking this should be more of a controller thing. Going to close the ticket for now. We'll address this a different way.
-
Allow :select to work just like :fields does in #find
1 comment Created 7 months ago by jnunemakerComments
jnunemaker
Sun May 31 18:43:48 -0700 2009
| link
Allowing :fields or :select to be used in find interchangeably. losed by ac5622c.
-
Allow defaulting the :fields selected by any find
3 comments Created 7 months ago by jnunemakerOnce documents start getting big they are slow to query unless you define the fields you want to return. Having a default list of keys to select would be handy. Maybe something like this would work:
class Foo include MongoMapper::Document default_keys :fname, :lname # etc, etc endDoing the above would mean that any find query would only select fname, lname, etc unless otherwise specified.
Comments
How about the following?
class Foo
include MongoMapper::Document define_select_group do |group| group.small( :fname, :lname ) group.medium( :fname, :lname, :dob ) group.large( :fname, :lname, :dob, :bio ) end endso you can specify select_group in the find
find(:all, :select_group => :small, :conditions => {:fname => "foo" })
jnunemaker
Mon Jul 27 07:56:51 -0700 2009
| link
This isn't really a solution to the original ticket but I like the idea. I would probably just say field_group instead of define_select_group and then use field_group in the find as well.
The original idea of the ticket is to not have to specify each time you query what fields should be picked and instead default so you never pick all the fields from a document that is huge (which would be really slow).
jnunemaker
Sun Aug 16 11:51:06 -0700 2009
| link
Closing this as it is included in #56 which is a more broad ticket for declaring scopes in general.
-
Comments
jnunemaker
Wed Jun 17 21:28:33 -0700 2009
| link
The more I think about this, the more I'm thinking it doesn't really make sense.
-
Make a simple way to override auto-generated id
1 comment Created 7 months ago by jnunemakerRight now you could just define generate_id to do this but it might be nice to have some kind of API for doing it. Maybe...
class Foo include MongoMapper::Document id :some_id_method # or a proc or something? endIf anyone has any thoughts on this, let me know.
Comments
jnunemaker
Fri Jun 26 20:55:21 -0700 2009
| link
All you have to do is set _id in the attributes and this works. You can also override generate_id.
-
Comments
jnunemaker
Thu May 28 22:24:08 -0700 2009
| link
First pass at this is implemented:
https://github.com/jnunemaker/mongomapper/commit/1f18c8cf46d06ae74ff80935096f44883da7ed73
jnunemaker
Sun May 31 18:48:04 -0700 2009
| link
I'm going to close this as it pretty much works when defining keys. The only thing left is association related and I'll do it when I do the associations.
-
Comments
jnunemaker
Fri Jun 26 20:53:55 -0700 2009
| link
Closing this for now as it might not be applicable.
-
I'm thinking of using this as the base:
http://not-naughty.rubyforge.org/
http://github.com/boof/not-naughty/tree/masterTried out validatable and it has some quirks. Not really its fault, but annoying.
Comments
jnunemaker
Thu May 28 21:18:53 -0700 2009
| link
Ended up using forked version of validatable. not naught had way too much magic for my liking.
Relevant commits:
First pass Enforcement






It doesn't lie, I'm just not using :safe => true ever to actually raise an exception. I have plans to make this option available.
Whoops, I just submitted a pull request to fix this (mrkurt@489d804). It "lies" in the sense that the document doesn't actually save, but it still returns true. :)
Why not use :safe => true every time with an option to opt out? I know it's an extra round trip, but it's scary for something to look successful when it's really not.