Activerecord with JDBC in JRuby

I have some code that works in “normal” RoR.

It doesn’t work in JRuby with the MySql JDBC adapter.

The query is:
@breakdowns = Client.find(:all,
:select => breakdown_select,
:conditions =>breakdown_conditions ,
:joins => breakdown_joins,
:group => breakdown_group,
:order=> ‘record_count desc’)

Which shows up in the log as:

Client Load (0.000000) SELECT clients.client_status as
breakdown_id,count(clients.client_status)as record_count FROM clients
left join programmes on clients.programme_id = programmes.id WHERE
(clients.programme_id = 12 ) GROUP BY clients.client_status ORDER BY
record_count desc

This is fine…
But when I try to access the “breakdown_id” column from the query
(clients.client_status as breakdown_id) it fails with:
NoMethodError (undefined method `breakdown_id’ for #<Client:
0xfd9b4d>):

eg.
for breakdown in @breakdowns
logger.info("breakdown_id= #{breakdown.breakdown_id})
end

This has been working fine until I tried to deploy with JRuby.

Any ideas… surely I can alias column names?

Cheers
Giorgio.

Uhmm…

Can you try do?:

for breakdown in @breakdowns
logger.info("breakdown_id= #{breakdown.id})
end

I have read that ActiveRecord always name de the primary key
column with the name “id”.

I have this table definition in a jruby program:

class Empresa < ActiveRecord::Base
set_table_name “si_Empresas”
set_primary_key “IdEmpresa”
has_many :usuarios, :class_name => “Usuario”, :foreign_key =>
“IdEmpresa”
has_and_belongs_to_many :perfiles,
:class_name => “Perfil”,
:join_table => “si_EmpresasPerfiles”,
:foreign_key => “IdEmpresa”,
:association_foreign_key => “IdPerfilEmpresa”
end

and then i use this with success:

Empresa emp = Empresa.find(2234)

puts “Empresa #{emp.id}”

giorgio wrote:

I have some code that works in “normal” RoR.

It doesn’t work in JRuby with the MySql JDBC adapter.

The query is:
@breakdowns = Client.find(:all,
:select => breakdown_select,
:conditions =>breakdown_conditions ,
:joins => breakdown_joins,
:group => breakdown_group,
:order=> ‘record_count desc’)

Which shows up in the log as:

Client Load (0.000000) SELECT clients.client_status as
breakdown_id,count(clients.client_status)as record_count FROM clients
left join programmes on clients.programme_id = programmes.id WHERE
(clients.programme_id = 12 ) GROUP BY clients.client_status ORDER BY
record_count desc

This is fine…
But when I try to access the “breakdown_id” column from the query
(clients.client_status as breakdown_id) it fails with:
NoMethodError (undefined method `breakdown_id’ for #<Client:
0xfd9b4d>):

eg.
for breakdown in @breakdowns
logger.info("breakdown_id= #{breakdown.breakdown_id})
end

This has been working fine until I tried to deploy with JRuby.

Any ideas… surely I can alias column names?

Cheers
Giorgio.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs