On Friday, December 28, 2012 12:09:38 PM UTC-8, Andrew Reynhout wrote:
>
> I'd like to pass a column list into a Dataset#select as an array, so that
> I have better control of which columns will be selected, e.g.:
>
> columns_wanted = [:id, :name]
> columns_wanted << :address if include_address?
> rows = DB[:entries].select(columns_wanted)
>
> This currently returns rows in an unexpected format:
>
> DB[:entries].select(columns_wanted).first
> => {:row=>"(1,\"Some One\",\"825 Victoria Ln\")"}
>
> Whereas columns specified as individual arguments returns the desired
> format:
>
> DB[:entries].select(:id, :name, :address).first
> => {:id=>"1", :name=>"Some One", :address=>"825 Victoria Ln"}
>
>
> Would this change break other use cases?
>
Yes. You should just splat the existing array:
DB[:entries].select(*columns_wanted).first
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/M3KtROg3e7gJ.
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.