I found that if I do something like (on MySQL):
File.all(:conditions => {‘files.deleted’ => false, ‘assets.deleted’ =>
false}, :include => :assets)
will only return Files which have at least 1 assets associated with it.
If i removed the assets.deleted = 0 condition, then it returns all
Files, and their assets (if any); which is how I expected things to
behave.
now I can do something like:
File.all(:conditions => ‘files.deleted AND (assets.file_id IS NULL OR
assets.deleted = 0)’, :include => :assets)
And it will return all Files, and their assets (if any)…but righting a
query like this every time I do an include (i.e. almost all my tables
has a deleted bit) seems a bit cumbersome, as I prefer the hash
conditions over the string version.
Is there any way around this? Thanks