Lorenzo Brito Morales
2011-Feb-14 06:56 UTC
Problem with activerecord,a object has no reference
http://pastie.org/1561681 Hi i got a problem that object has its fields initialize but no the reference to the objects, the table has its own id, and has 2 references keys, but i got only the fields not the objects so i have to query to bring it, module TodostagsHelper def viewtags(todo_) tags ="" todo_.todostags.each do |todotag_| ##prints ok the todotag_tags_id puts "imprimiendo #{todotag_.tags_id}" ##prints nil to the object todotag_.tag , its suppose to be initialize not? puts todotag_.tag tip = Tag.find(todotag_.tags_id) tags= tags.concat('','').concat(tip.name) end tags end end -- 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
2011-Feb-14 07:12 UTC
Re: Problem with activerecord,a object has no reference
On Feb 14, 6:56 am, Lorenzo Brito Morales <lorenzo.br...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> http://pastie.org/1561681 > Hi i got a problem that object has its fields initialize but no the > reference to the objects, > the table has its own id, and has 2 references keys, but i got only > the fields not the objects > so i have to query to bring it, > > module TodostagsHelper > > def viewtags(todo_) > > tags ="" > todo_.todostags.each do |todotag_| > > ##prints ok the todotag_tags_id > puts "imprimiendo #{todotag_.tags_id}" > ##prints nil to the object todotag_.tag , its suppose to be initialize not?It should be, but as your code stands it will be using tag_id to find a Tag object whereas the rest of your code is examining tags_id. What columns are actually on the table? Fred> puts todotag_.tag > > tip = Tag.find(todotag_.tags_id) > tags= tags.concat('','').concat(tip.name) > > end > > tags > end > > end-- 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.
Lorenzo Brito Morales
2011-Feb-14 07:44 UTC
Re: Re: Problem with activerecord,a object has no reference
for table tags id pk name string description string for table todos id pk todo string progreso string vencimiento date for table todostags id pk todos_id fk tags_id fk On Mon, Feb 14, 2011 at 1:12 AM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Feb 14, 6:56 am, Lorenzo Brito Morales <lorenzo.br...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> http://pastie.org/1561681 >> Hi i got a problem that object has its fields initialize but no the >> reference to the objects, >> the table has its own id, and has 2 references keys, but i got only >> the fields not the objects >> so i have to query to bring it, >> >> module TodostagsHelper >> >> def viewtags(todo_) >> >> tags ="" >> todo_.todostags.each do |todotag_| >> >> ##prints ok the todotag_tags_id >> puts "imprimiendo #{todotag_.tags_id}" >> ##prints nil to the object todotag_.tag , its suppose to be initialize not? > > It should be, but as your code stands it will be using tag_id to find > a Tag object whereas the rest of your code is examining tags_id. What > columns are actually on the table? > > Fred >> puts todotag_.tag >> >> tip = Tag.find(todotag_.tags_id) >> tags= tags.concat('','').concat(tip.name) >> >> end >> >> tags >> end >> >> end > > -- > 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. > >-- 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.
Lorenzo Brito Morales
2011-Feb-14 20:38 UTC
Re: Re: Problem with activerecord,a object has no reference
so, have to chante the names of the fk of the table todostasg ? On Mon, Feb 14, 2011 at 1:44 AM, Lorenzo Brito Morales <lorenzo.brito-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> for table tags > id pk > name string > description string > for table todos > id pk > todo string > progreso string > vencimiento date > for table todostags > id pk > todos_id fk > tags_id fk > > On Mon, Feb 14, 2011 at 1:12 AM, Frederick Cheung > <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> On Feb 14, 6:56 am, Lorenzo Brito Morales <lorenzo.br...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> wrote: >>> http://pastie.org/1561681 >>> Hi i got a problem that object has its fields initialize but no the >>> reference to the objects, >>> the table has its own id, and has 2 references keys, but i got only >>> the fields not the objects >>> so i have to query to bring it, >>> >>> module TodostagsHelper >>> >>> def viewtags(todo_) >>> >>> tags ="" >>> todo_.todostags.each do |todotag_| >>> >>> ##prints ok the todotag_tags_id >>> puts "imprimiendo #{todotag_.tags_id}" >>> ##prints nil to the object todotag_.tag , its suppose to be initialize not? >> >> It should be, but as your code stands it will be using tag_id to find >> a Tag object whereas the rest of your code is examining tags_id. What >> columns are actually on the table? >> >> Fred >>> puts todotag_.tag >>> >>> tip = Tag.find(todotag_.tags_id) >>> tags= tags.concat('','').concat(tip.name) >>> >>> end >>> >>> tags >>> end >>> >>> end >> >> -- >> 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.
Lorenzo Brito Morales
2011-Feb-15 02:36 UTC
Re: Re: Problem with activerecord,a object has no reference
hi i solve the problem with your advice, i just add the option foreign_key to the foreign keys thanks On Mon, Feb 14, 2011 at 2:38 PM, Lorenzo Brito Morales <lorenzo.brito-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> so, have to chante the names of the fk of the table todostasg ? > > On Mon, Feb 14, 2011 at 1:44 AM, Lorenzo Brito Morales > <lorenzo.brito-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> for table tags >> id pk >> name string >> description string >> for table todos >> id pk >> todo string >> progreso string >> vencimiento date >> for table todostags >> id pk >> todos_id fk >> tags_id fk >> >> On Mon, Feb 14, 2011 at 1:12 AM, Frederick Cheung >> <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>> >>> On Feb 14, 6:56 am, Lorenzo Brito Morales <lorenzo.br...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>> wrote: >>>> http://pastie.org/1561681 >>>> Hi i got a problem that object has its fields initialize but no the >>>> reference to the objects, >>>> the table has its own id, and has 2 references keys, but i got only >>>> the fields not the objects >>>> so i have to query to bring it, >>>> >>>> module TodostagsHelper >>>> >>>> def viewtags(todo_) >>>> >>>> tags ="" >>>> todo_.todostags.each do |todotag_| >>>> >>>> ##prints ok the todotag_tags_id >>>> puts "imprimiendo #{todotag_.tags_id}" >>>> ##prints nil to the object todotag_.tag , its suppose to be initialize not? >>> >>> It should be, but as your code stands it will be using tag_id to find >>> a Tag object whereas the rest of your code is examining tags_id. What >>> columns are actually on the table? >>> >>> Fred >>>> puts todotag_.tag >>>> >>>> tip = Tag.find(todotag_.tags_id) >>>> tags= tags.concat('','').concat(tip.name) >>>> >>>> end >>>> >>>> tags >>>> end >>>> >>>> end >>> >>> -- >>> 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.