ncbo / goo

Graph Oriented Objects (GOO) for Ruby. A RDF/SPARQL based ORM.
http://ncbo.github.io/goo/
Other
15 stars 6 forks source link

model .where method fails when attribute for seach is not in model #75

Closed dazza-codes closed 11 years ago

dazza-codes commented 11 years ago

This arose from using LinkedData::Models::Review in ontology_linked_data project, with an erroneous ':user' search instead of ':creator'. This is the cryptic error generated by goo:

  2) Error:
test_single_review(TestReviewsController):
NoMethodError: undefined method `[]' for nil:NilClass
    /home/dlweber/.rbenv/versions/1.9.3-p385/lib/ruby/gems/1.9.1/bundler/gems/goo-ff6f7f2abc1c/lib/goo/base/queries.rb:340:in `block in search_by_attributes'
    /home/dlweber/.rbenv/versions/1.9.3-p385/lib/ruby/gems/1.9.1/bundler/gems/goo-ff6f7f2abc1c/lib/goo/base/queries.rb:326:in `each'
    /home/dlweber/.rbenv/versions/1.9.3-p385/lib/ruby/gems/1.9.1/bundler/gems/goo-ff6f7f2abc1c/lib/goo/base/queries.rb:326:in `search_by_attributes'
    /home/dlweber/.rbenv/versions/1.9.3-p385/lib/ruby/gems/1.9.1/bundler/gems/goo-ff6f7f2abc1c/lib/goo/base/resource.rb:383:in `where'
    /data/src/ncbo/ontologies_api/controllers/reviews_controller.rb:24:in `block (2 levels) in <class:ReviewsController>'

This is an example of a correct call signature:

LinkedData::Models::Review.where :ontologyReviewed => {:acronym=>params[:acronym]}, :creator => {:username=>params[:username]}

This is an incorrect call signature:

LinkedData::Models::Review.where :ontologyReviewed => {:acronym=>params[:acronym]}, :user => {:username=>params[:username]}
msalvadores commented 11 years ago

got it. I'll look into it.

msalvadores commented 11 years ago

Note: the bug happens when there are unknown attributes + nested objects.

msalvadores commented 11 years ago

There is a follow up from this issue in #76.