I have a method which returns an array of records which I can't keep as a
pure scope because I need to do complex in-memory filtering not easy with
pure SQL.
accounts = current_user.accounts.select {|a| a.some_complex_method }
But I need to be able to scope-chain it for other purposes later, so I end
up re-scoping it:
accounts = Account.where(id: accounts.map(&:id)).order('name asc')
Unfortunately this issues a 2nd db call which isn't needed because all data
for the subsequent scope chains should be available from the original
result.
Is there a way for me to build an in-memory chainable scope for data
returned previously and already converted to array, without making extra db
calls? I realize stuff like offset will not reliably work with this
approach, but I don't need it for my use case.
Eugene
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/d5166487-ccdb-4ee6-bbe2-f300b77aabe5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.