What is the new way to check if a parent has child items? In rails 1.2.6 I did this: if @client.has_line_items? Client being the parent and line_items the children. Now that I have upgraded to rails 2.0.1 (on my way to current :-) ) I am getting this message: undefined method `has_line_items?'' for #<Client:0x7f3b093b01a0> How should I format the query now? Regards, Paul Thompson -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Paul, if @client.line_items.exists? Anthony Crumley http://commonthread.com On Mon, Apr 12, 2010 at 8:30 PM, Paul Jonathan Thompson <rails001-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> What is the new way to check if a parent has child items? In rails > 1.2.6 I did this: > > if @client.has_line_items? > > Client being the parent and line_items the children. > > Now that I have upgraded to rails 2.0.1 (on my way to current :-) ) I > am getting this message: > > undefined method `has_line_items?'' for #<Client:0x7f3b093b01a0> > > How should I format the query now? > > Regards, > > Paul Thompson > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Anthony, It''s better, but I''m not quite there yet. I am now getting: wrong number of arguments (0 for 1) Regards, Paul Thompson On 13 April 2010 13:56, Anthony Crumley <anthony.crumley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Paul, > > if @client.line_items.exists? > > Anthony Crumley> On Mon, Apr 12, 2010 at 8:30 PM, Paul Jonathan Thompson <rails001-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> >> What is the new way to check if a parent has child items? In rails >> 1.2.6 I did this: >> >> if @client.has_line_items? >> >> Client being the parent and line_items the children. >> >> Now that I have upgraded to rails 2.0.1 (on my way to current :-) ) I >> am getting this message: >> >> undefined method `has_line_items?'' for #<Client:0x7f3b093b01a0> >> >> How should I format the query now?-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Paul, Sorry, but I gave you the wrong method. It should have been ... unless @client.line_items.empty? Anthony Crumley http://commonthread.com On Mon, Apr 12, 2010 at 9:10 PM, Paul Jonathan Thompson <rails001-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Thanks Anthony, > > It''s better, but I''m not quite there yet. I am now getting: > > wrong number of arguments (0 for 1) > > Regards, > > Paul Thompson > > On 13 April 2010 13:56, Anthony Crumley <anthony.crumley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Paul, > > > > if @client.line_items.exists? > > > > Anthony Crumley > > > On Mon, Apr 12, 2010 at 8:30 PM, Paul Jonathan Thompson < > rails001-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> > >> What is the new way to check if a parent has child items? In rails > >> 1.2.6 I did this: > >> > >> if @client.has_line_items? > >> > >> Client being the parent and line_items the children. > >> > >> Now that I have upgraded to rails 2.0.1 (on my way to current :-) ) I > >> am getting this message: > >> > >> undefined method `has_line_items?'' for #<Client:0x7f3b093b01a0> > >> > >> How should I format the query now? > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Anthony, Did a little more homework and decided to use: unless @client.line_items.blank? as .blank? will not bomb on a nil condition and .empty? will. But thanks very much for pointing me in the right direction. Regards, Paul Thompson On 13 April 2010 14:16, Anthony Crumley <anthony.crumley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Paul, > > Sorry, but I gave you the wrong method. It should have been ... > > unless @client.line_items.empty? > > Anthony Crumley > http://commonthread.com > > On Mon, Apr 12, 2010 at 9:10 PM, Paul Jonathan Thompson <rails001@gmail.com> > wrote: >> >> Thanks Anthony, >> >> It''s better, but I''m not quite there yet. I am now getting: >> >> wrong number of arguments (0 for 1) >> >> Regards, >> >> Paul Thompson >> >> On 13 April 2010 13:56, Anthony Crumley <anthony.crumley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Paul, >> > >> > if @client.line_items.exists? >> > >> > Anthony Crumley >> >> > On Mon, Apr 12, 2010 at 8:30 PM, Paul Jonathan Thompson >> > <rails001-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> > wrote: >> >> >> >> What is the new way to check if a parent has child items? In rails >> >> 1.2.6 I did this: >> >> >> >> if @client.has_line_items? >> >> >> >> Client being the parent and line_items the children. >> >> >> >> Now that I have upgraded to rails 2.0.1 (on my way to current :-) ) I >> >> am getting this message: >> >> >> >> undefined method `has_line_items?'' for #<Client:0x7f3b093b01a0> >> >> >> >> How should I format the query now? >> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On Apr 13, 12:01 am, Paul Jonathan Thompson <rails...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks Anthony, > > Did a little more homework and decided to use: > > unless @client.line_items.blank? > > as .blank? will not bomb on a nil condition and .empty? will. >Not sure why you''d want to do that - if a has_many is returning nil (rather than an empty array) something has gone terribly, terribly wrong. Also, .blank? isn''t proxied like .empty? is - blank? will load the association then call the method; empty? is defined in AssociationCollection to do a direct SQL query if the association isn''t loaded, potentially skipping a bunch of unneeded object creation. Certainly not a big deal, but worth following the standard API for efficiency''s sake. --Matt Jones -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Maybe Matching Threads
- Rendering a Partial as an Alternative
- gem install rails (Errno::ENOENT) No such file or directory
- Advise sought: Upgrade from Rails 2.0.1 to current
- Problem saving parent and children using belongs_to, class_name, and foreign_key
- Upgrading rails project - version 1.2.6 to current (2.3.5)