Quick question , in a find statement, particularly the :conditions part.
if you see something like conditions => ["user = ?", user])
what would you be drawing the first "user" from and the second ? I'm
taking this from the AWDWR book.
If user is a column / method in the model , are you just repeat it
twice , or would you say
user = ?, tom ? I'm confused.
Let me make sure I got this right -
if the column name was user and then I did
user = "jack"
:conditions => ["user ?" <- this is the column, user <- this is jack] ?
Let me make sure I got this right -
if the column name was user and then I did
user = "jack"
:conditions => ["user ?" <- this is the column, user <- this is jack] ?
Stuart
Yes. Be sure to check your development log, since it will show the
full SQL query that was actually run and can give great insight into how
what you're passing in your find translates into the final query. I
recommend running a tail -f on the log in one window and experimenting
with different commands in script/console in another window side-by-side
for this purpose. Very educational.
Actually , I'm totally confused about what I'm seeing in the log . It
looks like there are multiple queries going on. The one that stands
out is the 2nd one , but I'm putting the find on the cdetails table
not the users.
part suggests to me you did something from the browser window, not the
console. When you load a page in your rails app in a browser rails is
going to make LOTS of SQL queries. Your syntax looks correct though.
Assuming that all the model relationships and tables are setup
correctly, from this...
If you just did that from the console, Rails would run just the one query on the Cdetails table. If you’re running it from the browser, there is probably some code referencing the user object(not just code that says user = 1) in there that you’re missing.