Where are T2 variables??
That’s what find_by_sql does: you’ll always get and instance of T1
(with some extra attributes though, can’t remember if the console will
show them by default. Also be careful doing what you;ve done because
you could easily have overwritten the id attribute with the one from
T2, which will cause havoc when you try and save the objects you’ve
loaded. Lastly with the write associations you can probably do without
the call to find_by_sql.
Where are T2 variables??
That’s what find_by_sql does: you’ll always get and instance of T1
(with some extra attributes though, can’t remember if the console will
show them by default. Also be careful doing what you;ve done because
you could easily have overwritten the id attribute with the one from
T2, which will cause havoc when you try and save the objects you’ve
loaded. Lastly with the write associations you can probably do without
the call to find_by_sql.
Fred
true,
but I believe I’m correct in saying that if you did
“select T1.*, T2.name as t2_name …”
it would correctly load the “t2_name” as an attribute of the T1 object.
On 27 Jun 2008, at 09:40, Matthew R. Jacobs wrote:
you could easily have overwritten the id attribute with the one from
“select T1.*, T2.name as t2_name …”
it would correctly load the “t2_name” as an attribute of the T1
object.
Yup that should work. You just won’t see t2_name if you’re messing
around in the console (except of course if you call attributes or
t2_name): the default output format in rails 2 just shows attributes
from the main table.
On 27 Jun 2008, at 09:40, Matthew R. Jacobs wrote:
you could easily have overwritten the id attribute with the one from
“select T1.*, T2.name as t2_name …”
it would correctly load the “t2_name” as an attribute of the T1
object.
Yup that should work. You just won’t see t2_name if you’re messing
around in the console (except of course if you call attributes or
t2_name): the default output format in rails 2 just shows attributes
from the main table.
Fred
yes your are right and i am tottaly accept but when i did that it throws
exeption “Attribute doesn’t exist in array…”
Yup that should work. You just won’t see t2_name if you’re messing
around in the console (except of course if you call attributes or
t2_name): the default output format in rails 2 just shows attributes
from the main table.
Fred
yes your are right and i am tottaly accept but when i did that it
throws
Yup that should work. You just won’t see t2_name if you’re messing
around in the console (except of course if you call attributes or
t2_name): the default output format in rails 2 just shows attributes
from the main table.
Fred
yes your are right and i am tottaly accept but when i did that it
throws
did what?
Fred
@tables= T1.find_by_sql("select T1.,T2. from T1 inner join T2on
T1.followup_id = T2.id where followups.userid = ‘41’ ")
puts @tables[:t2_name]
@tables= T1.find_by_sql("select T1.,T2. from T1 inner join T2on
T1.followup_id = T2.id where followups.userid = ‘41’ ")
puts @tables[:t2_name]
and you missed out the “T2.name as t2_name”;
@tables= T1.find_by_sql("select T1.*,T2.name AS t2_name from T1 inner join T2 on T1.followup_id = T2.id where followups.userid = ‘41’ ")
puts @tables.first[:t2_name]
Thanks Fred
Now it’s working the problem was in @tables.first[:t2_name],
also you are right console display only the attributes of the table that
i used in finding “T1”