On Apr 17, 5:43 am, yellowreign <ryanac...@gmail.com> wrote:
>
> Two weird things seem to happen:
>
> (1) Activity records are pulling in which don't belong to the user, in
> fact, when I look at my DB I'm not sure the Activity records even exist (do
> a sort by user_id in Activity, then I look at the dates when I don't find
> match by user_id)
>
> (2) when I look at my Rails server records, it seems to cycle through all
> of the users instead of just the one I'm looking for which would make it a
> resource hog even if the calculation was correct.
>
> I have tried the query two ways, but both yield the same [wrong] results.
> Please help!
>
> in the Activity model, I have this method:
>
> def self.calculate_user_job_points(customer, user_id)
>   Activity.sum(:amount , :conditions => [ "job_id IN (?) and user_id =?", 
> customer.jobs, user_id ])
> end
>
> I've also tried the query this way and it yields the same results:
>
>  Activity.where('job_id =? and user_id =?', customer.jobs, 
> user_id).sum("amount")
>

I don't think there's a lot that can be said without seeing the actual
sql that gets generated and the result versus the expected result
(with some sample data). There's nothing obviously incorrect with what
you've written, but then again I'm not 100% store what you're trying
to do

Fred

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to