Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Incorrect FK in nested models under Rails 3.2/PostgreSQL #22

Open
ealden opened this issue Jan 30, 2012 · 1 comment
Open

Incorrect FK in nested models under Rails 3.2/PostgreSQL #22

ealden opened this issue Jan 30, 2012 · 1 comment

Comments

@ealden
Copy link

ealden commented Jan 30, 2012

I am currently on Rails 3.2 with PostgreSQL as database, and the following example does not work as expected:

Foo.populate 10 do |foo|
    Bar.populate 10 do |bar|
        bar.foo_id = foo.id
    end
end

The entries for Bar should be linked to Foo through a foreign key. Instead the value of foo.id inside Bar seems to start from 0 always, thus, running a rake db:populate multiple times would cause the id of Foo to move forward (as it does not reset by default) and lead to Bar linking to the incorrect Foo.

This commit from route/populator@5c1da8c3784e6322c3d26f3b1c4511daeecb7a80 seems to fix this - might be a good idea to merge?

@gmccue
Copy link

gmccue commented Apr 11, 2012

Here is a temporary work-around for Postgre (discussed here: #18)

[Table1, Table2, Table3].each do |tbl|
  tbl.delete_all
  ActiveRecord::Base.connection.reset_pk_sequence!(tbl.table_name)
end

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants