hi I have two tables agencies contracts i have one statement like below @getdata=Agency.all(:joins=>:contracts, :select=>"agencies.*",:conditions=>["agencies.status =?",1 ]) i am able to access all data in agency but not able to access contracts data from above query please guide me how to do the above it is very critical -- Karthik.k Mobile - +91-9894991640 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
And what are the relationships between these models? Sijo -- Posted via http://www.ruby-forum.com/.
On Tue, Aug 11, 2009 at 11:03 AM, Sijo Kg <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > And what are the relationships between these models? > > > Sijo > -- > Posted via http://www.ruby-forum.com/.Hi Sijo It has the below relation has_and_belongs_to_many :contracts has_and_belongs_to_many :agencies -- Karthik.k Mobile - +91-9894991640> > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Karthik Kantharaj Ok One more thing please tell what you are trying to attain with the above query? Sijo -- Posted via http://www.ruby-forum.com/.
On Tue, Aug 11, 2009 at 11:14 AM, Sijo Kg <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > Hi Karthik Kantharaj > > Ok One more thing please tell what you are trying to attain with the > above query? > > Sijo >Hi sijo With the below query @getdata=Agency.all(:joins=>:contracts, :select=>"agencies.*",:conditions=>["agencies.status =?",1 ]) I want to access and retrieve the data from both tables condition both table id should be equal e.g agencies.id=contracts.id In the below method for getdata in @getdata do puts getdata.name end I am able to access agencies data but not contracts data I need to know how to access contracts data because i need to group them, one contract can have any number of agencies contract1 agency1 agency2 contract2 agency1 agency2 I have explained you my exact requirement sijo, i am stuck in this i need help Thanks -- Karthik.k Mobile - +91-9894991640> > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi you get agencies for each contract like Contract.all.each { |c| c.agencies } Here you get each contract information too For example Contract.all.each do |c| c.name #contract name c.agencies end Can collect it to an array like array = [] Contract.all.each do |c| array << [c,c.agencies] end and can iterate the array now Sijo -- Posted via http://www.ruby-forum.com/.
On Tue, Aug 11, 2009 at 12:03 PM, Sijo Kg <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > Hi > you get agencies for each contract like > > Contract.all.each { |c| c.agencies } > > Here you get each contract information too For example > > Contract.all.each do |c| > c.name #contract name > c.agencies > endHi Sijo Thank you In the below code Contract.all.each do |c| c.name #contract name c.agencies end i am not able to get c.agencies.name I have name in agencies table but i am not able to help me Plz -- Karthik.k Mobile - +91-9894991640> > Can collect it to an array like > > array = [] > Contract.all.each do |c| > array << [c,c.agencies] > end > and can iterate the array now > > > Sijo > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Karthik For example consider this data_array = [] Contract.all.each do |c| data_array << [c,c.agencies] end Now in view you can iterate thru this like data_array.each do |arr| puts arr[0].name arr[1].each do |sub_arr| puts sub_arr.name end end You can modify this according to your needs May be there some other easier methods Sijo -- Posted via http://www.ruby-forum.com/.
On Tue, Aug 11, 2009 at 12:36 PM, Sijo Kg <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > Hi Karthik > > For example consider this > > data_array = [] > Contract.all.each do |c| > data_array << [c,c.agencies] > end > > Now in view you can iterate thru this like > > data_array.each do |arr| > puts arr[0].name > arr[1].each do |sub_arr| > puts sub_arr.name > end > end > > You can modify this according to your needs May be there some > other easier methods > > > Sijo >Hi Sijo Thank you Thank you Great Thank you -- Karthik.k Mobile - +91-9894991640> > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Aug 11, 2009 at 12:43 PM, karthik k <cse.k.karthik-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Tue, Aug 11, 2009 at 12:36 PM, Sijo Kg < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> >> Hi Karthik >> >> For example consider this >> >> data_array = [] >> Contract.all.each do |c| >> data_array << [c,c.agencies] >> end >> >> Now in view you can iterate thru this like >> >> data_array.each do |arr| >> puts arr[0].name >> arr[1].each do |sub_arr| >> puts sub_arr.name >> end >> end >> >> You can modify this according to your needs May be there some >> other easier methods >> >> >> Sijo >> > > Hi Sijo > > Thank you Thank you > > Great Thank you > > -- > Karthik.k > Mobile - +91-9894991640 >hi sijo I did and got the output <table align="center" width="50%" bordercolor="#000000"> <% @data_array.each do |arr|%> <tr align="left" bgcolor="#0BA3C0"> <% if arr[1].length>0%> <th><%= arr[0].name%></th> <%end%> </tr> <%for sub_arr in arr[1]%> <tr> <td><%= sub_arr.name%></td> </tr> <%end%> <%end%> for the above table i am getting output as e.g contract1 agency1 agency2 contract2 agency1 agency2 Can i get in the below format contract1 agency1 agency2 contract2 agency1 agency2 agency3 I dont know how to split from <%for sub_arr in arr[1]%> Plz help -- Karthik.k Mobile - +91-9894991640> > > >> >> -- >> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---