Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Custom filter/search/column? (particularly: using "having")
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jeff Tratner  
View profile  
 More options Nov 3 2012, 9:24 pm
From: Jeff Tratner <jtrat...@gmail.com>
Date: Sat, 3 Nov 2012 18:24:35 -0700 (PDT)
Local: Sat, Nov 3 2012 9:24 pm
Subject: Custom filter/search/column? (particularly: using "having")

I'd like to add a custom search or filter method.  Basically I want to be
able to do a search or filter on a calculated column. if I were going to
write it as a direct query, I would do something like:

MyModel.having(["SUM(payments.payment_amount) >= ?", 100.0)

and bonus points for being able to use a custom select like

MyModel.select(["SUM(payments.payment_amount) AS payment_amount,

> mymodels.*"])

I'm just having a bit of trouble figuring out either:
1 - if this is already a part of railsadmin
2 - what elements need to be monkey patched or changed to hook in a search
attribute like this.  Any suggestions?

Just getting pointed to where to look to hack around with this would be
great...I admit the RailsAdmin code is a bit complicated for me.

I was thinking it would be simple to (at the very least) incorporate having
query by patching `all` to recognize `having` as an option. (since all gets
called to scope all other queries, not super difficult)

module RailsAdmin

>   module Adapters
>     module ActiveRecord
>       # monkey patch on RailsAdmin's ActiveRecord adapter to allow it to
> take in
>       # custom `having` parameters
>       def all_with_having(options = {}, scope = nil)
>         scope = all_without_having(options, scope)
>         scope.having(options[:having]) if options[:having]
>       end
>       alias_method_chain :all, :having
>     end
>   end
> end

so the next step is just to figure out adapt RailsAdmin's already existing
search methods to do this.

Any suggestions?

Best,

Jeff


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »