On Mar 11, 2011, at 10:42 AM, fuego wrote:
> Hi all,
>
> I did it with:
> hobo_index(Vlan, :conditions=>["ipv4network_id IS NULL"])
>
> instead of the non-working:
> hobo_index Vlan.apply_scopes(
> :search => [params[:search],:vlan, :name, :vlanname, :description],
> :order_by => parse_sort_param(:vlan, :switchingdomain, :vlanname),
> :network_id_is => false
> )
Unfortunately, one can't use the _is scopes to check for NULLs - it's not
exactly a Hobo issue, as the problem is that this doesn't work either:
Vlan.find(:all, :conditions => ['network_id = ?', nil])
(note: nil and false are decidedly different here - passing false generates SQL
like "network_id = 'false'" which is completely wrong)
ActiveRecord doesn't rewrite the query above into the desired SQL ("network_id
IS NULL"), so that's the source of the issue. Now that I think about it, this
is ultimately a SQL problem (as "network_id = NULL" wouldn't work even if you
could coax AR into spitting it out).
The following *does* work:
Vlan.find(:all, :conditions => { :network_id => nil })
(as AR can now decide what SQL to produce) but this isn't currently extensible
to anything besides equality checking - there's no way, for instance, to
produce an 'IS NOT NULL' condition.
For future reference, you may also want to consider watching the
development.log file (use tail -f on Unixy systems) as it will show in
real-time what SQL is being generated. Massively helpful when doing tricky
stuff with joins/includes/etc.
--Matt Jones
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" 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/hobousers?hl=en.