On Apr 9, 10:39 pm, gm gm <[email protected]> wrote:
> 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
Not really. When an include is done in a single query conditions apply
to all rows, which makes unobvious things like your first example
happen. You might be able to craft a named scope to alleviate the
typing work.
Fred
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---