I've pasted the code where I have a problem here:
http://progress-vs-perfection.blogspot.com/2007/11/issue-with-arrayempty.html
The bottom line is this: I have an object called document_group that
has many document_templates. In my controller, I create class
variable like so:
@document_group_templates = @document_group.document_templates
Then, in my view I have to decide to do some rendering, so I do this:
if !@document_group_templates.empty?
...do stuff
end
The issue is that .empty? always evaluates to true. For whatever
reason, the collection of document_templates on the document_group
does not get initialized.
I can look in my log file and see that the SQL to populate the array
is not triggered. That said,
a) if I do something such as @document_group_templates.inspect that
triggers the SQL to run that populates the array
b) if I do
if @document_group_templates.count > 0
...do stuff
end
the #count method also triggers the SQL to run.
All that said, shouldn't this statement:
@document_group_templates = @document_group.document_templates
have triggered the SQL to load the array in the first place? Is that
a bug of some sort?