Skip to content

Move column_names assignment inside returning_selections - #892

Open
mirelon wants to merge 1 commit into
zdennis:masterfrom
mirelon:patch-1
Open

Move column_names assignment inside returning_selections#892
mirelon wants to merge 1 commit into
zdennis:masterfrom
mirelon:patch-1

Conversation

@mirelon

@mirelon mirelon commented Jan 8, 2026

Copy link
Copy Markdown

When running the import, I was getting error from deep inside this gem:

undefined method 'column_names' for nil (NoMethodError)

Something is probably wrong on more layers, but the fix on this place is simple and safe, because column_names are not needed if there are no selections.

@jkowens

jkowens commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

I agree with avoiding the column_names lookup when there are no selections, but I don’t think we should move the assignment inside the map. That repeats the same lookup for every selection and makes the method harder to read.

Could we instead build selections first, then handle missing model metadata explicitly? For example:

column_names = Array(options[:model]&.column_names)

selections += Array(options[:primary_key]) if options[:primary_key].present?
selections += Array(options[:returning]) if options[:returning].present?
return selections if column_names.empty?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants