Ruby on Rails Sunday, October 30, 2011

On Sun, Oct 30, 2011 at 6:24 AM, Frederick Cheung <frederick.cheung@gmail.com> wrote:
Personally I would just use the raw sql in a call to delete_all. A
complicated use of arel isn't necessarily "better" or easier to use
than sql (portability concerns aside, but then the whole idea that you
can move any significantly sized app just by changing a line in
database.yml is a bit of a myth anyway).

you could do something like

   class Event < ..
     def self.duplicate_events
       event_alias = Event.arel_table.alias
       scoped.joins(event_alias).where(:subject_id =>
event_alias[:subject_id], ...).where(Event.arel_table[:id].gt(event_alias[:id]))
     end
   end

That results in the following error:

RuntimeError: unknown class: Arel::Nodes::TableAlias

Distilled down:

Event.joins(Event.arel_table.alias)

Any ideas?

And yeah… it seems like just putting SQL into a delete_all call is the easiest way to go.  Still interested in this Arel stuff though.

-- C

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment