[Rails] Re: Active Record Question

2011-08-28 Thread John Doe
That did the trick! Thanks! But, I am sorry I did not get your explanation. Forgive me, I am very new to Ruby and Rails. Could you please explain why it didn't work before, and why it worked your way? On Aug 27, 7:47 am, Frederick Cheung frederick.che...@gmail.com wrote: On Aug 27, 8:35 am,

[Rails] Re: Active Record Question

2011-08-28 Thread John Doe
Also, in my controller, I'd like to call the parent controller's method to format my json in a certain way...So instead of this: respond_to do |format| format.json { render :json = @projects.to_json(:include = [:apps]) } end I'd like to do something like this: result = nested data respond_to

[Rails] Re: Active Record Question

2011-08-27 Thread Frederick Cheung
On Aug 27, 8:35 am, John Doe john.doe.hello.wo...@gmail.com wrote: In my projects controller, I am trying to do this: @projects = Project.find(:all, :include = [:books]) My hope is to get a nested data structure back that looks something like: Well you what you get back is an array of

Re: [Rails] Re: active record question

2010-07-09 Thread Michael Pavling
On 9 July 2010 03:08, RailsFan Radha li...@ruby-forum.com wrote: I come from a db world. Can someone interpret this please, self.questions.reject{|q| q.nil?}.all this explains what .reject does: http://ruby-doc.org/core/classes/Enumerable.html#M003126 So essentially, the line takes the

[Rails] Re: active record question

2010-07-09 Thread Frederick Cheung
On Jul 9, 8:44 am, Michael Pavling pavl...@gmail.com wrote: On 9 July 2010 03:08, RailsFan Radha li...@ruby-forum.com wrote: I come from a db world. Can someone interpret this please, self.questions.reject{|q| q.nil?}.all this explains what .reject

Re: [Rails] Re: active record question

2010-07-09 Thread Dave Aronson
On Fri, Jul 9, 2010 at 05:28, Frederick Cheung frederick.che...@gmail.com wrote: For what it's worth, reject{|q| q.nil?} is the same as compact ... if the collection is an Array. Without more context, I don't know if that's so. The compact method is on that, not Enumerable. -Dave --

[Rails] Re: active record question

2010-07-08 Thread RailsFan Radha
I come from a db world. Can someone interpret this please, self.questions.reject{|q| q.nil?}.all I'm overwhelmed by the syntax in the second line, self.questions.reject{|q| q.nil?}.all def needed_questions self.questions.reject{|q| q.nil?}.all end something like that. i can somewhat

[Rails] Re: active record question

2010-07-08 Thread Marnen Laibow-Koser
RailsFan Radha wrote: I come from a db world. Can someone interpret this please, self.questions.reject{|q| q.nil?}.all I'm overwhelmed by the syntax in the second line, self.questions.reject{|q| q.nil?}.all Go look up the relevant functions (especially reject) in the documentation.

[Rails] Re: active record question

2010-07-03 Thread Me
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

[Rails] Re: active record question

2010-07-01 Thread RailsFan Radha
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

[Rails] Re: Active record question

2008-09-07 Thread Frederick Cheung
On Sep 7, 1:52 am, Phlip [EMAIL PROTECTED] wrote:    Appointment.find( :all, :include = :tasks,                          :conditions = { :'tasks.project_id' = 1} ) In summary, provide enough :has_many = :through to get to the keying table, then put it into your :include and :conditions.

[Rails] Re: Active record question

2008-09-06 Thread Phlip
Mark Studebaker wrote: I'm not quite sure how to get at this data using Actrive record.. I'm trying to get all the appointments made for a particular project. I'm using four models, Projects, Tasks, Resources and Appointments. The SQL gets me what I'm looking for but how do I do it

[Rails] Re: Active record question

2008-09-06 Thread Phlip
Mark Studebaker wrote: What I was trying to do was something like this project.appointments to display all the appointments for a specific project. Briefly, since you seem to have more experience with raw SQL than ActiveRecord (better than the other way around!;), try inspect_sql to see