Ok, I patched finder.rb and added a group_by_for_collection method.

So, far the only problem I've found is that klass.count() now returns
an
array (the group by element) so I to massage that value.
I'm sure sure if there is a mechanism to submit this back for
consideration for
future releases or not.

 # PATCH Oct 08  JM added :group line and changed count = klass.count
to count_prelim = Klass.count and the following assignment to count
      # create a general-use options array that's compatible with
Rails finders
      finder_options = { :order =>
build_order_clause(options[:sorting]),
                         :conditions => all_conditions,
                         :group => group_by_for_collection,
                         :joins => joins_for_collection,
                         :include => active_scaffold_joins.empty? ?
nil : active_scaffold_joins}

      # NOTE: we must use :include in the count query, because some
conditions may reference other tables
      count_prelim = klass.count(finder_options.reject{|k,v|
[:order].include? k})

      if group_by_for_collection
        count = count_prelim.length
      else
        count = count_prelim
      end

      # END PATCH Oct 08
On Oct 3, 1:12 pm, joelm <[EMAIL PROTECTED]> wrote:
> Might be the best way, I'm looking into that.  Any guidance as to
> likely patch points?
>
> On Oct 3, 11:57 am, Ed W <[EMAIL PROTECTED]> wrote:
>
> > joelm wrote:
> > > I'm trying to generate a report with a top level that is grouped.  It
> > > appears from previous threads that the best solution is to create a
> > > view since there is no way to specify Group By (:group) in AS's find_
> > > methods.  That works to some level.
>
> > > But this fails if I need to winnow down the records BEFORE the group
> > > by.
>
> > > i.e.  SELECT * FROM info GROUP BY type
>
> > > works fine.  But what I really want is:
> > >    SELECT * FROM info WHERE user_id = current_user.id  GROUP BY type
>
> > > current_user.id is dynamic and in a stored procedure would be a
> > > parameter.
>
> > > If I had control of the find method, this should work fine since
> > > the :conditions => {user_id = current_user.id}
> > > would be added to the SQL and be executed BEFORE the group by by the
> > > database engine.
>
> > > But, in a view, I would have to write:
> > >    create view 'testView'  => "SELECT * FROM info GROUP BY type"
>
> > > Presuming that there are many records of the same 'type' from
> > > different 'users', the user_id
> > > value in that view is indeterminate, so I can't use it as a
> > > condition.  If my view were to be:
> > >  "SELECT * FROM info GROUP BY user_id, type"
>
> > > Then I could filter out the user_id's I want, but I'd then be left
> > > with multiple rows for each 'type'.
> > > (That is, all the remaining users.)
>
> > > So, the real question: Is there ANY way to add a :group clause to the
> > > AS search?  Or allow me to
> > > substitute in my own SQL for the search or does anyone have some
> > > solution that I'm missing?
> > > (And is there a reason that AS does NOT allow :group?  i.e. is there a
> > > fundamental reason this shouldn't work or is it just an implementation
> > > issue of
> > > too many things that need doing?
>
> > Patch the code?
>
> > Ed W
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to