Closed leadbaxter closed 9 years ago
I'm not sure why you're calling first
on the result of sum. Sum should give you the totally all by itself. What precisely are you doing to get that error?
The only reason I'd be calling first
is because I don't know what I'm doing. I haven't been able to explore any further because the error stops me. If I could, then I would soon learn whether I needed to write .first
or not!
I can reproduce the error as simply as:
Weather.sum(:inches_f)
Other than that, I'm doing all the CRUD operations, sorting, and grouping - the whole nine yards. But sum()
does not work for me at all. Incidentally, I hit some other of the aggregate type functions that failed. But it was like 2am and I don't remember which ones.
I guess I'm not sure what to say. You're right it should work, and that's an odd error. If you can put up a repo that will reliably produce that we can take a look.
leadbaxter/cdq_test
I included a bunch of unit tests to show the problem, plus some other problems I was telling you I found, as well as a bunch of sanity tests (mostly because I wanted to see whether a lot of the Enumerable methods worked or not.)
A couple of things you may or may not care about when installing:
If you need any more information just give me a holler!
Thanks for looking at it.
Oh, OK. I see what's going on. You're using features that are in head, but not in the latest gem. I need to release v 1.0.3 apparently.
That fixes all but the last two of my tests, the ones using the indexing. I modeled mine after what I saw in your tests, but it still didn't work.
Weather.sort_by(:readings)[0]
Any ideas?
I figured out my problem... can't use negative indexes. Makes sense.
Weather[2]
instead of
Weather[-1]
works perfectly. I have 25 successful tests running.
Thanks for helping and for jumping right on it!
It could just be me (first time using CDQ) but I can't get sums to work.
I have a pretty simple Weather entity. No matter what I do, I get the same error.
After that, I would assume I could write:
Here's the error resulting from any of the above queries: