Hi, Anybody please tell me the tutorial way to connect and retrieve data using foreign key in a connected table. -- With Regards Palani Kannan. K -- 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.
On 23 September 2010 07:58, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > Anybody please tell me the tutorial way to connect and retrieve data using > foreign key in a connected table.I think I may have already answered this in my reply to your other question, have a look at the Rails Guide on ActiveRecord Relationships. But probably start with Getting Started guide. Colin -- 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.
Dear Collin, I feel that I am not clearly explained you, here I included the clear explanation about the problem. I included models, controller and View. Please, find the mistake in it and tell me. *name model* has_many :city, :foreign_key => "name_id" has_many :country, :foreign_key => "name_id" * city model* belongs_to :name *country model* belongs_to :name *In Name Controller* @names = Name.find(:all, :conditions=>{:first_name => params[:gm], :second_name => params[:sp]}, :include => [ :city, :country ]) *In Name View* <% @names.each do |name| %> <%= name.age %> <% end %> <% @names.cities.each do |city| %> <%= city.local_area %> <% end %> <% @names.countries.each do |country| %> <%= country.state %> <% end %> On 23 September 2010 09:56, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 23 September 2010 07:58, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > Hi, > > > > Anybody please tell me the tutorial way to connect and retrieve data > using > > foreign key in a connected table. > > I think I may have already answered this in my reply to your other > question, have a look at the Rails Guide on ActiveRecord > Relationships. But probably start with Getting Started guide. > > Colin > > -- > 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. > >-- With Regards Palani Kannan. K -- 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.
http://railscasts.com/episodes/47-two-many-to-many -- 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.
PalaniKannan K wrote:> *name model* > has_many :city, :foreign_key => "name_id" > has_many :country, :foreign_key => "name_id" > *has_many models should be pluralized class name < ActiveRecord::Base has_many :cities has_many :countries end -- Posted via http://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-/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.
Dear Ar Chron, Thanks for your correction. The error solved, but its not still showing the values for <%= city.local_area %> <%= country.state %> On 23 September 2010 16:30, Ar Chron <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> PalaniKannan K wrote: > > > *name model* > > has_many :city, :foreign_key => "name_id" > > has_many :country, :foreign_key => "name_id" > > * > > has_many models should be pluralized > > class name < ActiveRecord::Base > has_many :cities > has_many :countries > end > -- > Posted via http://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-/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. > >-- With Regards Palani Kannan. K -- 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.
Hi, I tried with *In View* <% @names.each do |name| %> <%= name.age %> <% name.cities.each do |city| %> <%= city.local_area %> <% name.countries.each do |country| %> <%= country.state %> <% end %> This shows no error with no output of city.local_area and country.state On 23 September 2010 12:45, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Dear Collin, > > I feel that I am not clearly explained you, here I included the clear > explanation about the problem. I included models, controller and View. > Please, find the mistake in it and tell me. > > *name model* > has_many :city, :foreign_key => "name_id" > has_many :country, :foreign_key => "name_id" > * > city model* > belongs_to :name > > *country model* > belongs_to :name > > *In Name Controller* > @names = Name.find(:all, :conditions=>{:first_name => params[:gm], > :second_name => params[:sp]}, :include => [ :city, :country ]) > > *In Name View* > > <% @names.each do |name| %> > <%= name.age %> > <% end %> > > <% @names.cities.each do |city| %> > <%= city.local_area %> > <% end %> > > <% @names.countries.each do |country| %> > <%= country.state %> > <% end %> > > > On 23 September 2010 09:56, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 23 September 2010 07:58, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> wrote: >> > Hi, >> > >> > Anybody please tell me the tutorial way to connect and retrieve data >> using >> > foreign key in a connected table. >> >> I think I may have already answered this in my reply to your other >> question, have a look at the Rails Guide on ActiveRecord >> Relationships. But probably start with Getting Started guide. >> >> Colin >> >> -- >> 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. >> >> > > > -- > With Regards > Palani Kannan. K > >-- With Regards Palani Kannan. K -- 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.
On 23 September 2010 16:34, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: Why are you asking the same question in multiple threads? Colin> Hi, > > I tried with > > In View > > <% @names.each do |name| %> > <%= name.age %> > <% name.cities.each do |city| %> > <%= city.local_area %> > <% name.countries.each do |country| %> > <%= country.state %> > <% end %> > > This shows no error with no output of city.local_area and country.state > > On 23 September 2010 12:45, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> Dear Collin, >> >> I feel that I am not clearly explained you, here I included the clear >> explanation about the problem. I included models, controller and View. >> Please, find the mistake in it and tell me. >> >> name model >> has_many :city, :foreign_key => "name_id" >> has_many :country, :foreign_key => "name_id" >> >> city model >> belongs_to :name >> >> country model >> belongs_to :name >> >> In Name Controller >> @names = Name.find(:all, :conditions=>{:first_name => params[:gm], >> :second_name => params[:sp]}, :include => [ :city, :country ]) >> >> In Name View >> >> <% @names.each do |name| %> >> <%= name.age %> >> <% end %> >> >> <% @names.cities.each do |city| %> >> <%= city.local_area %> >> <% end %> >> >> <% @names.countries.each do |country| %> >> <%= country.state %> >> <% end %> >> >> On 23 September 2010 09:56, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>> >>> On 23 September 2010 07:58, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>> wrote: >>> > Hi, >>> > >>> > Anybody please tell me the tutorial way to connect and retrieve data >>> > using >>> > foreign key in a connected table. >>> >>> I think I may have already answered this in my reply to your other >>> question, have a look at the Rails Guide on ActiveRecord >>> Relationships. But probably start with Getting Started guide. >>> >>> Colin >>> >>> -- >>> 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. >>> >> >> >> >> -- >> With Regards >> Palani Kannan. K >> > > > > -- > With Regards > Palani Kannan. K > > -- > 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.
Hi, Extreme sorry for all and Colin, I posted in several thread... I will not post repeated posts once again. -- Palani Kannan -- 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 are probably getting an "undefined method ''cities'' for #<Array:blah blah>" error. Address each hierarchy level in turn... <% @names.each do |name| %> <% name.cities.each do |city| %> <%= city.local_area %> <% end %> <% end %> <% @names.each do |name| %> <% name.countries.each do |country| %> <%= country.state %> <% end %> <% end %> -- Posted via http://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-/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.
PalaniKannan K
2010-Sep-28 13:14 UTC
Re: Re: Re: Connecting several tables in single database
Dear All, Finally, tables are connecting and displaying data once i provided "set_primary_key". I read about role of "foreign key" in connecting table. But, I dont know the role of "primary_key" in connecting tables. Anybody knows it??? -- With Regards, Palani Kannan. K -- 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.