rails / arel

A Relational Algebra
2.06k stars 390 forks source link

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

Closed krainboltgreene closed 7 years ago

krainboltgreene commented 8 years ago

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

vipulnsward commented 8 years ago

@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.

krainboltgreene commented 8 years ago

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

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
rafaelfranca commented 7 years ago

Fixed on master.