Hi, select * from table1 inner join table2 on table1.foreign_key table2.foreign_key select * from table1 inner join table2 on table1.foreign_key table2.foreign_key join table3 on table2.foreign_key=table3.foreign_key These are the SQL commands, I need to apply it in Rails. Kindly tell me the syntax in Rails to apply these SQL commands instead of sql_query. -- 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 Sep 13, 11:59 am, PalaniKannan K <kpalanikan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > select * from table1 inner join table2 on table1.foreign_key > table2.foreign_key > > select * from table1 inner join table2 on table1.foreign_key > table2.foreign_key join table3 on table2.foreign_key=table3.foreign_key > > These are the SQL commands, I need to apply it in Rails. Kindly tell me the > syntax in Rails to apply these SQL commands instead of sql_query. >Take a look at the :joins option to find (or the joins scope modifiying thing in rails 3) Fred> -- > 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sep 13, 6:10 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 13, 11:59 am, PalaniKannan K <kpalanikan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > > select * from table1 inner join table2 on table1.foreign_key > > table2.foreign_key > > > select * from table1 inner join table2 on table1.foreign_key > > table2.foreign_key join table3 on table2.foreign_key=table3.foreign_key > > > These are the SQL commands, I need to apply it in Rails. Kindly tell me the > > syntax in Rails to apply these SQL commands instead of sql_query. > > Take a look at the :joins option to find (or the joins scope > modifiying thing in rails 3) > > Fred >I think has_many :through might also be what you''re looking for. You can avoid writing SQL 99% of the time if you learn how to use the various flavors of ActiveRecord associations. Jeff -- 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 13 September 2010 19:54, Jeff <cohen.jeff-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 13, 6:10 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > On Sep 13, 11:59 am, PalaniKannan K <kpalanikan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > > > > select * from table1 inner join table2 on table1.foreign_key > > > table2.foreign_key > > > > > select * from table1 inner join table2 on table1.foreign_key > > > table2.foreign_key join table3 on table2.foreign_key=table3.foreign_key > > > > > These are the SQL commands, I need to apply it in Rails. Kindly tell > me the > > > syntax in Rails to apply these SQL commands instead of sql_query. > > > > Take a look at the :joins option to find (or the joins scope > > modifiying thing in rails 3) > > > > Fred > > > > I think has_many :through might also be what you''re looking for. You > can avoid writing SQL 99% of the time if you learn how to use the > various flavors of ActiveRecord associations. >Dear Jeff, In model I can apply has_many and belongs_to option. How I can apply those tables in Controller and View... I am new bee... I tried with some tutorials, every tutorial i m getting instructions to use has_many and belongs_to in model. I am getting problem with controllers and view to use "find" with foreign_keys if I use those options in model.> > Jeff > >-- 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.