Duane Johnson
2005-Apr-26 05:29 UTC
Does the paginate method count rows with a "join" for you?
I''m using this pagination code and getting a SQL syntax error out of
it:
sql_conditions = "(genre_id = 14)" # This line is a simplification of
actual code
@movie_pages, @movies = paginate :movie, :per_page => 10, :conditions
=> sql_conditions, :join => "LEFT JOIN genres_movies ON movies.id
movies_id"
And the resulting 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 ''LEFT JOIN genres_movies ON movies.id = movies_id WHERE (genre_id
= 14)'' at line 1:
SELECT COUNT(*) FROM movies m , LEFT JOIN genres_movies ON movies.id movies_id
WHERE (genre_id = 14)
Notice the ''m'' followed by a comma. I did my homework and
found that
this is indeed what the ActiveRecord::Base#count method says it is
supposed to be doing:
def count(conditions = nil, joins = nil)
tbl_var_name = joins ? table_name[0,1].downcase : ""
sql = "SELECT COUNT(*) FROM #{table_name} #{tbl_var_name} "
sql << ", #{joins} " if joins
add_conditions!(sql, conditions)
count_by_sql(sql)
end
But my question is WHY? Most importantly, why the comma? Under what
circumstances would you ever want a comma after the table name and its
abbreviation?
--
Duane Johnson
(canadaduane)
Jarkko Laine
2005-Apr-26 05:45 UTC
Re: Does the paginate method count rows with a "join" for you?
Duane, On 26.4.2005, at 08:29, Duane Johnson wrote:> > But my question is WHY? Most importantly, why the comma? Under what > circumstances would you ever want a comma after the table name and its > abbreviation?There''s a ticket and a patch for this in Trac: http://dev.rubyonrails.com/ticket/1156 //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Duane Johnson
2005-Apr-26 05:50 UTC
Re: Does the paginate method count rows with a "join" for you?
Rails developers ROCK! Thank-you, Jarkko. On 4/25/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> Duane, > > On 26.4.2005, at 08:29, Duane Johnson wrote: > > > > But my question is WHY? Most importantly, why the comma? Under what > > circumstances would you ever want a comma after the table name and its > > abbreviation? > > There''s a ticket and a patch for this in Trac: > http://dev.rubyonrails.com/ticket/1156 > > //jarkko > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > >-- Duane Johnson (canadaduane)