On Aug 9, 10:26 pm, Michael Lang <[email protected]> wrote: > Would it be possible to enhance the Dataset#get so that an array can be > passed and get back an array? > > i.e. > > charges, payments, balance = DB[:billing_headers].filter(:billing => > 5).get(:charges, :payments, :balance) > > Essentially, a shorthand for: > > DB[:billing_headers].filter(:billing => 5). > select(:charges, :payments, :balance). > map{|bh| [bh[:charges], bh[:payments], bh[:balance]}
For simple cases, it's easy, but it's difficult in more complex cases. It works in pretty much all cases now because there is only one column returned. Think about: DB[:billing_headers].get(:charges.sql_function, :payments - :balance) I suppose you could automatically alias if you have more than 1 column, but that might have negative effects if the column is referenced anywhere else (e.g. in a order by). DB[:a].join(:b, :id=>:b_id).order(:id).get(:a__id, :b__id___bid) Here, the order(:id) is not ambiguous because the selection is "a.id, b.id AS bid". However, if you start aliasing a.id, since id is no longer in the selection, it will be ambiguous, since it appears in both of the underlying tables. These issues are possible to work through, given enough logic in the method, but in cases like this I think it's better to force the user to deal with it manually using select and map. Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" 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/sequel-talk?hl=en.
