Forum: Ruby on Rails Some strange questions about SQL

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Charlie (Guest)
on 2006-04-19 19:16
1. Table dealings has the field: id(int(11)), inout(varchar(11))
If I use this select:
@deals = Dealing.find(:all,:condition=>["id = ? and inout =
?","1","in"])
then rails will return error with the tips of SQL syntax error
if I change it to :
@deals = Dealing.find(:all,:condition=>["dealings.id = ? and
dealings.inout = ?","1","in"])
than it will be ok. Why? I think the former select should be working
well and do not know the reason.

2. Suppose the relationships between the following tables:
users has_many dealings
dealings belongs_to user
@user = User.find(params[:id])
@user.dealings.count(["inout = ?","in"]) How the sentence will be
transfered into SQL? The rails return error with the tips of SQL syntax
error,because it get the SQL :  SELECT * FROM dealings WHERE
(dealings.user_id = '1' and (dealings.inout = 'in'))  Why the generated
SQL is in this kind error syntax and not :  SELECT * FROM dealings WHERE
(dealings.user_id = '1') and (dealings.inout = 'in') ?

Thanks
This topic is locked and can not be replied to.