Skip to content

UUID associations are not set #8

Open

Description

@antulik
FixtureBot.define do
  user :alice do
    email "one@mail.com"
  end

  project :blah do
    name "Project 1"
    user :alice
  end
end

outputs projects.yml

blah:
  id: 1afb5dc2-d94e-556a-b311-1d74d0a0e136
  name: Project 1

Expected project.user_id to be set

Using 1883091
Using rails 8.1.2

Activity

  1. siklodi-mariusz commented on Mar 13, 2026

    @siklodi-mariusz

    I was testing the gem and ran into the same issue. The problem seems to be caused by a missing foreign_key constraint.
    The code relies on the presence of FK to establish associations.

    So there are currently two workarounds:

    1. Add the missing FK constraint. Then the association IDs will be correctly assigned in the generated fixtures.
      add_foreign_key :projects, :users
    2. Manually assign the ID if adding FK is not an option (using the same method used internally to generate the deterministic IDs)
      FixtureBot.define do
        user :alice do
          email "one@mail.com"
        end
      
        project :blah do
          name "Project 1"
          use_id FixtureBot::Key::Integer.generate(:users, :alice)
        end
      end

    However, I still consider this a bug and expect this missing FK to be handled by fixturebot.

  2. antulik commented on Mar 14, 2026

    @antulik
    Author

    I can confirm adding foreign keys fixes it 👍

    However, I still consider this a bug and expect this missing FK to be handled by fixturebot.

    I agree

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions