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
And what are the relationships between these models?
Sijo
On Tue, Aug 11, 2009 at 11:03 AM, Sijo Kg
[email protected]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
Hi Karthik Kantharaj
Ok One more thing please tell what you are trying to attain with the
above query?
Sijo
On Tue, Aug 11, 2009 at 11:14 AM, Sijo Kg
[email protected]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
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
On Tue, Aug 11, 2009 at 12:03 PM, Sijo Kg
[email protected]wrote:
c.agencies
end
Hi 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
On Tue, Aug 11, 2009 at 12:36 PM, Sijo Kg
[email protected]wrote:
Now in view you can iterate thru this like
Sijo
Hi Sijo
Thank you Thank you
Great Thank you
–
Karthik.k
Mobile - +91-9894991640
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
karthik
10
On Tue, Aug 11, 2009 at 12:43 PM, karthik k [email protected]
wrote:
data_array = []
end
Thank you Thank you
Great Thank you
–
Karthik.k
Mobile - +91-9894991640
hi sijo
I did and got the output
<% @data_array.each do |arr|%>
<% if arr[1].length>0%>
<%end%>
<%for sub_arr in arr[1]%>
</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
<%= arr[0].name%> |
<%= sub_arr.name%> |