rails/arel

InsertManager#insert doesn't return self, not allowing it to be chainable

krainboltgreene opened this issue · 3 comments

Seems like most methods on these Managers are chainable but oddly this one isn't?

@krainboltgreene many other managers, or other methods from this manager don't return self as well(some are setters). Whats the use case you would like this to return self.

@vipulnsward Is that actually true? Here's the methods that are chainable:

  • SelectManager#skip, SelectManager#lock, SelectManager#on, SelectManager#group, SelectManager#from, SelectManager#join, SelectManager#outer_join, SelectManager#having, SelectManager#project, SelectManager#distict, SelectManager#distinct_on, SelectManager#order, SelectManager#with, SelectManager#take,
  • UpdateManager#take, UpdateManager#order, UpdateManager#table, UpdateManager#where, UpdateManager#set
  • InsertManager#into
  • DeleteManager#take, DeleteManager#from

I mean it seems like it should chain, in the same way UpdateManager#set chains.

table = Arel::Table.new(:persons)
query = table.where(table[:id] => 1).set(table[:name] => "Kurtis")
string = query.sql

table = Arel::Table.new(:persons)
query = table.insert(table[:name] => "Kurtis")
string = query.to_sql

Instead I have to write (for no discernible reason):

table = Arel::Table.new(:persons)
query = table.tap { |t| t.insert(table[:name] => "Kurtis") }
string = query.to_sql

Fixed on master.