Posts [ 10 ]

Topic: Refactor into scope

I can't quite figure out how to refactor this into a scope... I'm thinking of scoping the Post object and passing it in the user into the lambda, but its the joins and relationships I'm having a problem with.Here is the User model method I'd like to get into a scope or just perform it via SQL.

Basically , a user can make a post with a team or event association....and sometimes an event might be a team event, hence the uniq call. I just want to return posts associated with that user. Using rails 3.

Re: Refactor into scope

Actually the best way would be to combine the two queries you're triggering into a single query union. ActiveRecord doesn't support union queries as of Rails 2.3 (I don't know if that's the case in Rails 3), so there are 3 roads u can go down:

1. https://github.com/tsmango/union2. write yourself your own sql query and then find_by_sql3. forget all of this and follow the suggestions above, which will trigger 2 separate queries.