If your models are set up correctly you can do '@user.questions' for
the collection. You can set up a method or named_scope maybe on the
user model:
def needed_questions
self.questions.reject{|q| q.nil?}.all
end
something like that.
On Jul 1, 9:37 pm, RailsFan Radha <li...@ruby-forum.com> wrote:
> You could either use the find_by_sql method or the :joins method. (As
> someone has stated earlier that avoid find_by_sql for performance and
> maintanence reasons)
>
> sample sql to put in find_by_sql in your model
>
> select question_id from responses r1
> where not exists
> (select question_id from question q )
>
> using :joins. (probably this would be better )
>
> questions.find( :joins => "LEFT OUTER JOIN responses ON question_id =
> responses.question_id" :conditions => "responses.id is null")
>
> gurus, please comment on this.
>
> thanks,
> radha.
>
> badnaam wrote:
> > I have three models, Question, Response and User
>
> > User has many question, :through Responses
>
> > My response table has 3 main columns response, question_id and
> > user_id.
>
> > The use case is lets say the user can respond to 100 question, but
> > during a session he responds to 20. How do I find out the ones he has
> > not respondeded to. In this case the response table will have 20
> > records and I woukd like to show the user the rest of the 80 he has
> > not responded to.
>
> > Thanks
>
> --
> Posted viahttp://www.ruby-forum.com/.
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment