Giter VIP home page Giter VIP logo

model_subsets's People

Contributors

cblock avatar gdlx avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

model_subsets's Issues

Querying subset values after model creation fails if value is not assigned initially

Hi and thanks for developing this gem under open source license.

Consider the following model of a rails 3.2 with mongoid 3.0.6:

class Product
  include Mongoid::Document
  include ModelSubsets
  field :name, type: String
  field :description, type: String
end

Here are the steps to reproduce the error

DefineI a fieldset on Product using

fieldset = Product.fieldset :shipping_fields, :length

Create a subset (not really sure what the conceptual difference between fieldset and subset is, guessing from the code that fieldset is more like a class while subset is more like a class instance):

Product.subset :shipping, add: fieldset

create new product instances:

p1 = Product.create! name: 'My Product'
p2 = Product.create! name: 'My Product', length: 20

Query for length on p2 returns 20 (as expected), while query for length on p1 fails with an error:

p1.length
NoMethodError: undefined method `length' for #<Product:0x007fb7848b9640>
from /Users/cblock/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-
3.0.6/lib/mongoid/attributes.rb:225:in `method_missing'

Also p1.subset_fields fails with an error (code comments say it returns the current subsets fields list

p1.subset_fields
NameError: undefined local variable or method `subset' for #<Product:0x007fb7848b9640>
from /Users/cblock/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-
3.0.6/lib/mongoid/attributes.rb:225:in `method_missing'

Question: Is it me using the gem in a wrong way or is it a bug?

Add-On: How can I restrict subset fields to a certain type or add validations to them?

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.