#169 ✓resolved

Using named bind variables in AR conditions

Reported by neongrau | February 21st, 2010 @ 04:47 PM

i'm preferring to use named bind variables for some dynamic filtering on the db and with optional ferret searches.

naturally i got errors because aaf was just expecting an array for the AR conditions. :(

after hacking around i ended with an evil twin plugin for aaf consisting of this:


module ActsAsFerret
# combine our conditions with those given by user, if any def self.combine_conditions(conditions, additional_conditions = [])

returning conditions do
  if additional_conditions && additional_conditions.any?
    if additional_conditions[1].is_a?(Hash)
      # use named bind variables
      cust_opts = additional_conditions.dup
      cust_opts[1].merge!({:aaf_id_array => conditions[1]})
      cust_opts.first << " AND " << conditions.first.gsub(/\?/, ':aaf_id_array')
      logger.debug "cust_opts: #{cust_opts.inspect}"
      return cust_opts
      logger.debug "cust_opts: #{cust_opts.inspect}"
      conditions.first << " and " << cust_opts.shift

end end

this surely may not be the best solution but at least it seems to work for now.
i think this would be a nice addition to the plugin.

but after i got this lousy solution i wondered...

wouldn't it be more elegant to just wrap
model_class.with_scope(:find => find_options) do... ...end

around the .find and .count calls?
and just omit the combine_conditions altogether?

Comments and changes to this ticket

  • Jens

    Jens May 29th, 2010 @ 02:33 PM

    • State changed from “new” to “resolved”

    since that commit you can call find_with_ferret on named or dynamic scopes and expect the same results as if the conditions were given to aaf directly.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Shared Ticket Bins

People watching this ticket