Skip to content

Commit

Permalink
Fix for single column tables (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsantobuono authored Feb 7, 2025
1 parent d747015 commit 9c281f6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Error when dumping single-column tables. [@lsantobuono]
- Bug with null foreign key to back to auxiliary `has_one` association with not matching names. E.g. user has many profiles and has one default profile, profile belongs to user.
- Ignored columns handling.
- Dump relations for records that were dumped earlier with relations excluded.
Expand Down Expand Up @@ -136,3 +137,4 @@ Initial release. [@palkan], [@Envek]
[@cmer]: https://github.com/cmer "Carl Mercier"
[@nhocki]: https://github.com/nhocki "Nicolás Hock-Isaza"
[@gazay]: https://github.com/gazay "Alex Gaziev"
[@lsantobuono]: https://github.com/lsantobuono ""
2 changes: 1 addition & 1 deletion lib/evil_seed/relation_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,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|
Hash[model_class.column_names.zip(row)]
Hash[model_class.column_names.zip(Array(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 @@ -70,3 +70,6 @@ class Reaction < 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 @@ -72,5 +72,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 @@ -64,3 +64,8 @@
{ user: users[1], default: true, name: "Profile for user 1", title: "Title for user 1" },
{ user: users[2], default: true, 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 @@ -19,6 +19,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

0 comments on commit 9c281f6

Please sign in to comment.