-1

I'm trying to count the fields in a table, and the returned SQL isn't generated properly.

What am I doing wrong?

ds is the dataset:

term = 'abouts'
puts ds.count(:id).where(kind: term)       # => app.rb:179:in `<main>': undefined method `where' for 115:Integer (NoMethodError)

I am thinking aggregate methods can have conditionals like WHERE.

How can I fix this?

the Tin Man
  • 150,910
  • 39
  • 198
  • 279
Rich_F
  • 1,287
  • 3
  • 15
  • 38
  • You're getting an error because you're adding a query to the result of a count, which Ruby knows is a syntax error, and therefore it becomes an off-topic question. Please see "[ask]", "[Stack Overflow question checklist](https://meta.stackoverflow.com/questions/260648)" and "[MCVE](https://stackoverflow.com/help/minimal-reproducible-example)" and all their linked pages and "[How To Ask Questions The Smart Way](http://catb.org/esr/faqs/smart-questions.html)" especially the last one. – the Tin Man Jan 05 '20 at 03:40
  • If you read the `Sequel` documentation, queries can be added anywhere. The question was valid. How can a resulting error be an off-topic question? It __IS__ the question. – Rich_F Jan 23 '20 at 06:54

1 Answers1

-1

Found it:

puts ds.where(kind: term).count
Rich_F
  • 1,287
  • 3
  • 15
  • 38
  • Looks like a query and a count to me. Not sure why it's got a -1 either. It IS the answer to a valid question. Oh right, SO. – Rich_F Jan 23 '20 at 06:55