Code Monkey home page Code Monkey logo

mongomodel's People

Contributors

jgrubbs avatar kalarani avatar max-power avatar revcbh avatar spohlenz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mongomodel's Issues

Scopes not working anymore on has_many association proxy

class User < MongoModel::Document
    has_many :posts
end

class Post < MongoModel::Document
    belongs_to :user
    property :state, String
    scope :published, where(:state => 'published')
 end

Post.published => is working.
User.first.posts.published => throws an error: "undefined method 'published' for Array"

this was working till i did a bundle install this morning.

How to use 'OR' within a scope

How would I go about using mongo's $or functionality within mongomodel? I have two scopes that I need to merge as an OR.

scope :expires_in_future, -> { where({:expires_at.gte => Time.now}) }
scope :expires_null, -> { where({:expires_at => :nil }) }

thanks

Compatibility With Mongo 2.6? (Failed to create index)

We are using MongoModel, Wheelhouse and are unable to get them working with Mongo 2.6. Are these compatible?

mongo (1.9.2) lib/mongo/collection.rb:1086:in `rescue in generate_indexes'
mongo (1.9.2) lib/mongo/collection.rb:1079:in `generate_indexes'
mongo (1.9.2) lib/mongo/collection.rb:552:in `create_index'
mongomodel (0.5.2) lib/mongomodel/support/instrumented_collection.rb:97:in `block in create_index'
activesupport (3.2.17) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.17) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.17) lib/active_support/notifications.rb:123:in `instrument'
mongomodel (0.5.2) lib/mongomodel/support/instrumented_collection.rb:125:in `instrument'
mongomodel (0.5.2) lib/mongomodel/support/instrumented_collection.rb:96:in `create_index'
mongomodel (0.5.2) lib/mongomodel/document/indexes.rb:40:in `block in ensure_indexes!'
mongomodel (0.5.2) lib/mongomodel/document/indexes.rb:39:in `each'
mongomodel (0.5.2) lib/mongomodel/document/indexes.rb:39:in `ensure_indexes!'
mongomodel (0.5.2) lib/mongomodel/support/scope.rb:192:in `ensure_indexes!'
mongomodel (0.5.2) lib/mongomodel/support/scope.rb:159:in `_find'
mongomodel (0.5.2) lib/mongomodel/support/scope.rb:165:in `_find_and_instantiate'
mongomodel (0.5.2) lib/mongomodel/support/scope.rb:43:in `to_a'
mongomodel (0.5.2) lib/mongomodel/support/scope/finder_methods.rb:29:in `first'
mongomodel (0.5.2) lib/mongomodel/document/scopes.rb:14:in `first'
wheelhouse-core (1.0.18) app/models/wheelhouse/site.rb:37:in `for_request'
wheelhouse-core (1.0.18) lib/wheelhouse/middleware/set_site.rb:21:in `site_for'
wheelhouse-core (1.0.18) lib/wheelhouse/middleware/set_site.rb:12:in `call'
request_store (1.0.5) lib/request_store/middleware.rb:9:in `call'
lib/middleware/caching_with_request_forgery_protection.rb:8:in `call'
lib/middleware/default_headers.rb:8:in `call'

Using mongomodel on Rails 3.0.0.beta3 causes error.

Hi,

I just tried mongomodel on Rails 3.0.0.beta3 and encountered the following error:
No such file to load -- active_support/core_ext/object/metaclass (LoadError)

The metaclass.rb exists until Rails 3.0.0.beta but is missing from beta3.

Thanks in advance.

Collection#build syntactic surgar

What do you think of adding to Collection

alias_method :build, :<<

It just looks a little more readable to build up collections from value hashes with:

collection.build(:name => "Test", :value => 10)

instead of:

collection << {:name => "Test", :value => 10}

Specify foreign_key for belongs_to

We are trying to do something like

class Application
    belongs_to :job, class: Job, foreign_key: :source_id
end

So that when we do some_application.job it returns jobs by source_id and when setting some_application.job = job we would what it to set the job id reference to job.source_id.

Is this possible with mongomodel?

GridFS capability

Are there any plans to interface with GridFS or is there anyway to do it currently?

Rails 3.1 deprecation warnings

I fixed some of the rails 3.1 deprecation warnings.
unfortunatly my commits are a little clustered, so here a quick overview of what to change:

Fix path warnings:
https://github.com/max-power/mongomodel/blob/master/lib/mongomodel/railtie.rb#L20

Fix class_attributes warnings:
https://github.com/max-power/mongomodel/blob/master/lib/mongomodel/support/map.rb#L15-16
https://github.com/max-power/mongomodel/blob/master/lib/mongomodel/support/collection.rb#L17

haven't tackled the other ones.

Adds config.mongo_model to application.rb
https://github.com/max-power/mongomodel/blob/master/lib/mongomodel/railtie.rb#L3

Adds ActiveSupport load hook to MongoModel::Document
https://github.com/max-power/mongomodel/blob/master/lib/mongomodel/document.rb#L31

Should the delete method be public

The delete instance method in persistence is public. Calling this would bypass :destroy callbacks and could lead to some data integrity issues. I would think delete should be private. Or am I missing something?

Use :transformer option on find to instantiate models

i found out about the :transformer option on the mongo ruby drivers find method. from the docs:

:transformer (Block) โ€” default: nil โ€” a block for tranforming returned documents. This is normally used by object mappers to convert each returned document to an instance of a class.

then i tried something like this in the console and it worked great.

transformer = lambda {|doc| doc.delete('_type').constantize.from_mongo(doc) }
collection.find({}, {:transformer => transformer })

but i couldn't get the _find or _find_and_instantiate method (mongomodel::scope) running without breaking tests.
maybe you can have a look at it?

Association a la ActiveRecord

Hi,

I am going to like the MongoModel.
It is simpler and more straightforward than other mongo mappers.

Well, I have a question.

I wrote the following two classes:

class Group < MongoModel::Document
  property :name, String
  has_many :members
end

class Member < MongoModel::Document
  property :name, String
  belongs_to :group
end

Then I tested them:

g = Group.create(:name => 'X')
g.members << Member.new(:name => 'Alice')
g.members << Member.new(:name => 'Bob')

from_db = Group.find(g.id)
puts from_db.members.size

I expected '2' as the result by analogy with ActiveRecord.
But I got '0' instead.

Is this intentional?

MongoOptions and symbols pointing to arrays

Since the changes in MongoModel::Reference the queries for array or collection properties are broken:
it used to work with symbols, but now it only works with strings

see my example:

class Article < MongoModel::Document
  property :tags, Array, :default => []
end

Article.create(:tags => ['a', 'b', 'c'])
Article.where(:tags => 'a').count  # error
Article.where('tags' => 'a').count # works as expected

i tracked the error down to the MongoOptions::extract_condtions method:
https://github.com/spohlenz/mongomodel/blob/master/lib/mongomodel/support/mongo_options.rb#L38-43

Model.new(nil) breaks

Calling a Document initializer with nil breaks instead of treating the nil like an empty hash. This just causes a few bugs when converting ActiveRecord models into MongoModel::Documents. This could be fixed with a nil check in the initialize method in concerns/attributes.rb.

Stack level too deep saving Collections of EmbeddedDocument

I'm having a problem where I have a document with a property that is a Collection of EmbeddedDocuments. I can save it fine the first time, but when I reload the record, add another embedded document, and save it again, I get a stack level too deep error on the save callbacks.

I haven't found the problem, but the following spec recreates it:

describe "callbacks on many embedded documents" do
  define_class(:ChildThingDocument, EmbeddedDocument) do
    include MongoModel::CallbackHelpers
    property :name, String
  end

  define_class(:ParentDocument, Document) do
    property :things, Collection[ChildThingDocument]
  end

  it "should call callbacks on all embedded documents when adding a new one" do
    parent = ParentDocument.create!
    parent.things = Collection[ChildThingDocument].new
    parent.things << ChildThingDocument.new(:name => "Thing One")
    parent.save!
    parent = ParentDocument.find(parent.id)
    parent.things << ChildThingDocument.new(:name => "Thing Two")
    parent.save!
  end
end

Document how to use replica sets, perhaps add to mongomodel.yml template

I have been using Wheelhouse CMS for a project for over the last year along with Compose.io (formerly MongoHQ) which recommends using replica sets. For a while I would receive a notice from compose.io that one of my replica sets would be stepping down in favor of the other and I would have to manually switch out the database.yml file. However, after some digging I realized that mongomodel supports the use of replicas. I only found this, though, after deeply reviewing the source of mongomodel, here in particular:
https://github.com/spohlenz/mongomodel/blob/master/lib/mongomodel/support/configuration.rb#L45

To figure out what replicas should be I had to dig into the mongo gem. Also worth noting, mongomodel depends on a pretty old version of mongo so I had to look back to 1.8.6, they are currently at 1.12.0. There I noticed that replicas where just strings of the hostname and port concatenated.

After reviewing the source I realized that all that need to change was a couple lines of my database.yml (wheelhouse.yml in wheelhouse world).

old config:

  production:
    database: database_name
    host: some.host.com
    port: 12345
    username: username
    password: password

new config:

  production:
    database: database_name
    replicas:
      - some.host.com:12345
      - another.host.com:12345
    username: username
    password: password

Anyway, I think this should be simpler for someone to find when they first review the mongomodel readme and perhaps even when they generate the mongomodel.yml.

Type casting on numeric fields interprets blank as zero instead of nil

The current type casting code won't let numeric fields be set to nil when set from an empty string. This is a problem in a web application when trying to set fields from the form params. A blank form field should indicate nil and not zero.

class MyModel < MongoModel::Document
property :value, Integer
end

model = MyModel.new(:value => "")
model.value # = 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.