Git Product home page Git Product logo

redis_orm's People

Contributors

dminin avatar german 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

redis_orm's Issues

Does not redis_orm support HABTM?

I created 2 models

class User < RedisOrm::Base
  property :name, String

  has_many :books
end

class Book < RedisOrm::Base
  property :title, String

  has_many :users, as: :authors
end

And

user = User.create(name: 'Kent Beck')
user.books << Book.create(title: 'Refactoring')

But this code fails as follows:

       undefined method `pluralize' for :authors:Symbol

How should I do in this case?
has_many looks like not support HABTM
https://github.com/german/redis_orm/blob/master/lib/redis_orm/associations/has_many.rb#L7

Unable to build ActiveRecord associations ("Couldn't find [Model name] without an ID" error)

When building a has_one or belongs_to association that maps to an ActiveRecord model, a lookup is done in each of the association types for an old association that will later be cleared. However, when the lookup happens when there is no prior association, it fails. As such:

1. @comment = Comment.new(:message => 'Awesome Comment')
2. @comment.user = User.first # User is ActiveRecord
3. @comment.save

... would fail on line 2 because of the way the lookup is done for a has_one and belongs_to lookup with:

Couldn't find User without an ID

The lookup is made in lib/redis_orm/associations/belongs_to.rb, on lines 43-44,

# we need to store this to clear old association later
old_assoc = self.send(foreign_model_name)

... that calls foreign_model_name method that finds the record using the id value it gets from Redis, which returns nil if never previously associated. When nil is passed to an ActiveRecord model's find method, ActiveRecord raises an error because find_by_ids checks to see if there are 0, 1, or many ids being passed, and raising an error if the length is 0. (See: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/finder_methods.rb#L244)

When old_assoc is later checked to see if the old associated records (if !old_assoc.nil? / if old_assoc), the best fix, IMO, would be to add rescue nil when sending foreign_model_name, or adding a rescue clause in foreign_model_name, such as:

old_assoc = self.send(foreign_model_name) rescue nil

Another option is to adding some check during foreign_model_name to see if an association exist before finding the associated record, return nil before attempting to find the associated record.

Holla which method you like and I can help patch.

Allowing property to store array and hash

Is it theoretically hard to store array and hash as a property? These two types are pretty basic so I want to know if it is possible to monkey patch these two in.

Bump version on Rubygems

Hi @german,

I see some changes in master. Any chance you could push a new version as I believe it's currently broken.

Thanks in advance!

Allow overriding the ID type

It would be useful to override the id property to allow using unique Strings instead of incremental IDs or UUIDs.

NoMethodError: undefined method `incr' for nil:NilClass

Hi @german,

Thanks a lot for the gem.

I tried to replicate the example in the README and using the current master@2aa6160. Unfortunately, when trying to create or call .save on a new class, I'm running into the following issue:

class Article < RedisOrm::Base
  property :title, String
  has_many :comments
end

class Comment < RedisOrm::Base
  property :body, String
  property :moderated, RedisOrm::Boolean, :default => false
  index :moderated
  belongs_to :article
end
[12] pry(main)> article = Article.create :title => "DHH drops OpenID on 37signals"
NoMethodError: undefined method `incr' for nil:NilClass

Do you happen to have an idea by any chance? It looks $redis is nil:

    def get_next_id
      if @@use_uuid_as_id[model_name]
        @@uuid.generate(:compact)
      else
        $redis.incr("#{model_name}:id")
      end
    end

Thanks in advance!

how clean user:ids

For example:
When 'user:1' has expired,the 'user:1' must be removed. But user:ids also contain 1.

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.