Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

problem with filter shortcut method #57

Open
siemionides opened this issue Oct 7, 2014 · 1 comment
Open

problem with filter shortcut method #57

siemionides opened this issue Oct 7, 2014 · 1 comment

Comments

@siemionides
Copy link
Contributor

Hello,
today I've encountered the weird issue.
I have a model "Badge" in my Datomic db, here's it's ruby's representation:

 require 'diametric'

  class Badge
    include Diametric::Entity
    include Diametric::Persistence::Peer

    attribute :category, Ref
    attribute :date, DateTime
    attribute :description, String
    attribute :enum_value, String
    attribute :enumeration, String, :cardinality => :many
    attribute :id, UUID
    attribute :name, String
    attribute :type, Ref
    attribute :value, Double
    attribute :week, Integer
    attribute :year, Integer
  end

Im relying on Peer API, JRuby.
I want to get the badges with value >= 10.

Following code works fine:
badges = Diametric::Query.new(Badge, nil, true).filter(:>, :value, 9)
the badges.inspect returns
#<Diametric::Query:0x33de4104 @conditions={}, @filter_values=[9], @conn_or_db=nil, @filters=[[(> ?value ?valuevalue)]], @model=Badge, @resolve=true, @filter_attrs=[:value]>

and I'm free to iterate over set with

 badges.each do |badge|
      Grape::API.logger.info badge.inspect
  end

BUT when I'm trying to use shortcut method
badges = Badge.filter(:>, :value, 9)

the badges.inspect returns
#<Diametric::Query:0x1e7a60f7 @conditions={}, @filter_values=[9], @conn_or_db=:>, @filters=[[(?value ?valuevalue)]], @model=Badge, @resolve=true, @filter_attrs=[:value]>

(please mind the @conn_or_db or @filters keys)

and when i'm trying to iterate over set I'm being given

ArgumentError: The second arg should be a database.
    diametric/DiametricPeer.java:270:in `q'
    /Users/michalsiemionczyk/.rvm/gems/jruby-1.7.15/gems/diametric-0.1.3-java/lib/diametric/persistence/peer.rb:191:in `q'
    /Users/michalsiemionczyk/.rvm/gems/jruby-1.7.15/gems/diametric-0.1.3-java/lib/diametric/query.rb:117:in `each'
    /Users/michalsiemionczyk/Projects/yeti-backend/app/services/profiles/filtered_profiles_service.rb:37:in `query_for_date_filtered'

which points to the badges.each do |badge| .

I guess it might a bug relating to definition of filter shortcut method,

@yokolet
Copy link
Contributor

yokolet commented Oct 10, 2014

Would you try badges = Badge.filter(nil, :>, :value, 9) ?
The first argument is connection or nil for Peer. The filter shortcut is tested in rspec, but arguments are not the same as REST. Sorry about bad documentation. I added one line in query doc.
Probably, I should consider API design to make it clear.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants