true}) do |entry|
UserMailer.send_competition_open_email(entry, entry.user)
end
entry.user is always nil…
yet i can see in my SQL logs it tries to get it. But fails. Any ideas?
Entry Load (0.6ms) SELECT entries.* FROM entries WHERE entries.approved = 1 AND (entries.id >= 0) ORDER BY entries.id ASC LIMIT 1000
User Load (1.4ms) SELECT users.* FROM users WHERE (users.id
IN (1,2,3))
User Load (0.4ms) SELECT users.* FROM users WHERE users.id
= 1 LIMIT 1
yet i can see in my SQL logs it tries to get it. But fails. Any ideas?
Entry Load (0.6ms) SELECT entries.* FROM entries WHERE entries.approved = 1 AND (entries.id >= 0) ORDER BY entries.id ASC LIMIT 1000
User Load (1.4ms) SELECT users.* FROM users WHERE (users.id
IN (1,2,3))
User Load (0.4ms) SELECT users.* FROM users WHERE users.id
= 1 LIMIT 1
Probably one or more of your entries does not have an associated user.
Put in some diagnostic code that checks for entry.user nil and
displays the entry data, including id. Then have a look at all your
users and see if there is one that has that value in user_id.
so then it’s unlikely to be anything to do with :include. You can see
it doing stuff like
SELECT users.* FROM users WHERE users.id = 1 LIMIT 1
in your logs - if you run that query outside of rails do you get a row
back?
if that gets you a row and/or if User.find(some_entry.user_id) gets
rows back then i’d whip out the debugger and step into the user
accessor method to see what is happening
Fred
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.