Incorrect counts in rails 2.3
Reported by Diegorv | March 21st, 2009 @ 10:01 PM
I have this code
def self.completa(estado_id, cidade_id, bairro_id, segmento_id, pagina, limit = 5)
campos_padrao.estado(estado_id).cidade(cidade_id).bairro(bairro_id).segmento(segmento_id).joins.paginate(:per_page => limit, :page => pagina)
end
named_scope :campos_padrao, lambda { |*args|
{
:select=> (args.first ||
"anuncios.codcli,
anuncios.codseg,
anuncios.nomefanta,
anuncios.irmao,
anuncios.endereco,
anuncios.num,
anuncios.complemento,
anuncios.cep,
anuncios.bairro,
anuncios.cidade,
anuncios.uf,
anuncios.fone,
anuncios.fax,
anuncios.email,
anuncios.site,
anuncios.descricao,
anuncios.fig_anuncio,
anuncios.contrato,
anuncios.uf_anunciar,
anuncios.permalink,
cidades.cidade as cidade_nome,
estados.nome as estado_nome,
segmentos.nome as segmento
") }
}
named_scope :segmento, lambda { |*args|
if (args.first != "todos_segmentos")
{ :conditions => ["anuncios.codseg = ?", args.first] }
else
{ }
end
}
named_scope :estado, lambda { |*args|
{
:conditions => ["anuncios.uf = ?", args.first]
}
}
named_scope :cidade, lambda { |*args|
if (args.first != "todas_cidades")
{ :conditions => ["anuncios.cidade = ?", args.first] }
else
{ }
end
}
named_scope :bairro, lambda { |*args|
if (args.first != "todos_bairros")
{ :conditions => ["anuncios.bairro LIKE ?", "%#{args.first}%"] }
else
{ }
end
}
I get this error.
ctiveRecord::StatementInvalid (Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
anuncios.codseg,
anuncios.nomefanta,
' at line 1: SELECT count(anuncios.codcli,
anuncios.codseg,
anuncios.nomefanta,
anuncios.irmao,
anuncios.endereco,
anuncios.num,
anuncios.complemento,
anuncios.cep,
anuncios.bairro,
anuncios.cidade,
anuncios.uf,
anuncios.fone,
anuncios.fax,
anuncios.email,
anuncios.site,
anuncios.descricao,
anuncios.fig_anuncio,
anuncios.contrato,
anuncios.uf_anunciar,
anuncios.permalink,
cidades.cidade as cidade_nome,
estados.nome as estado_nome,
segmentos.nome as segmento
) AS count_anuncios_codcli_anuncios_codseg_anuncios_nomefanta_anuncios_irmao_anuncios_endereco_anuncios_num_anuncios_complemento_anuncios_cep_anuncios_bairro_anuncios_cidade_anuncios_uf_anuncios_fone_anuncios_fax_anuncios_email_anuncios_site_anuncios_descricao FROM `anuncios` INNER JOIN `estados` ON `estados`.uf = `anuncios`.uf INNER JOIN `cidades` ON `cidades`.codcid = `anuncios`.cidade INNER JOIN `segmentos` ON `segmentos`.codseg = `anuncios`.codseg WHERE (anuncios.uf = 'AC') ):
/Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:223:in
wp_count'
/Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:235:in
call'
/Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:235:in
wp_count'
/Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:85:in
paginate'
/Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/collection.rb:87:in
create'
/Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:76:in
paginate'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:in
with_scope'
Comments and changes to this ticket
-
Mislav March 21st, 2009 @ 11:34 PM
- State changed from new to duplicate
This is a bug in Rails.
See previous ticket, #264
-
Mislav March 21st, 2009 @ 11:36 PM
- State changed from duplicate to invalid
Oops, that ticket is only related to this problem. I meant to say that this was already reported on the mailing list.
In any case, we have to see what Rails will do with this. So far I think they haven't patched it.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Everyone's favorite Ruby library for pagination of practically anything!