Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for single column tables #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/evil_seed/relation_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def dump_has_many_associations!
# @return [Array<Hash{String => String, Integer, Float, Boolean, nil}>]
def fetch_attributes(relation)
relation.pluck(*model_class.column_names).map do |row|
row = [row] if model_class.column_names.size == 1
Hash[model_class.column_names.zip(row)]
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/db/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ class Vote < ActiveRecord::Base
belongs_to :votable, polymorphic: true
belongs_to :user
end

class Version < ActiveRecord::Base
end
2 changes: 2 additions & 0 deletions test/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@ def create_schema!
t.references :role, foreign_key: { on_delete: :cascade }
t.index %i[user_id role_id], unique: true
end

create_table :versions
end
end
5 changes: 5 additions & 0 deletions test/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@
{ user: users[1], name: "Profile for user 1", title: "Title for user 1" },
{ user: users[2], name: "Profile for user 2", title: "Title for user 2" },
])

Version.create!([
{ id: 1},
{ id: 2},
])
1 change: 1 addition & 0 deletions test/evil_seed_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def setup
config.root('Role') do |root|
root.exclude(/\Arole\.(?!roles_users\z)/) # Take only join table and nothing more
end
config.root('Version')

config.ignore_columns("Profile", :name)
end
Expand Down