Some strange questions about SQL

  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 =
    then rails will return error with the tips of SQL syntax error
    if I change it to :
    @deals = Dealing.find(:all,:condition=>[“ = ? 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’) ?


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