oren
2010-Apr-28 19:09 UTC
@content.keys.build works even when @content.keys is empty array. how?
my models: content has_many keys I don''t understand how is it possible that empty array will have ''build'' method? @content = Content.create(:text => ''test'') => #<Content id: 3, text: "test", created_at: "2010-04-28 19:04:19", updated_at: "2010-04-28 19:04:19"> @content.keys => [] but this works. can someone explain how can it be? @content.keys.build => #<Key id: nil, name: nil, content_id: 3, created_at: nil, updated_at: nil> Thanks -- 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.
Frederick Cheung
2010-Apr-28 21:16 UTC
Re: @content.keys.build works even when @content.keys is empty array. how?
On Apr 28, 8:09 pm, oren <orengo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> my models: content has_many keys > I don''t understand how is it possible that empty array will have > ''build'' method?Because it''s not actually an array - it''s an association proxy. Fred> > @content = Content.create(:text => ''test'') > => #<Content id: 3, text: "test", created_at: "2010-04-28 19:04:19", > updated_at: "2010-04-28 19:04:19"> > > @content.keys > => [] > > but this works. can someone explain how can it be? > @content.keys.build > => #<Key id: nil, name: nil, content_id: 3, created_at: nil, > updated_at: nil> > > Thanks > > -- > 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 athttp://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.
oren
2010-Apr-28 22:06 UTC
Re: @content.keys.build works even when @content.keys is empty array. how?
got it. too bad .class don''t shows me Array.. On Apr 28, 9:16 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 28, 8:09 pm, oren <orengo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > my models: content has_many keys > > I don''t understand how is it possible that empty array will have > > ''build'' method? > > Because it''s not actually an array - it''s an association proxy. > > Fred > > > > > > > @content = Content.create(:text => ''test'') > > => #<Content id: 3, text: "test", created_at: "2010-04-28 19:04:19", > > updated_at: "2010-04-28 19:04:19"> > > > @content.keys > > => [] > > > but this works. can someone explain how can it be? > > @content.keys.build > > => #<Key id: nil, name: nil, content_id: 3, created_at: nil, > > updated_at: nil> > > > Thanks > > > -- > > 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 athttp://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 athttp://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.