You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
one:
title: "My first post"account_id: 1labels: one, two
labels.yml
one:
text: "Label 1"two:
text: "Label 2"
and use them here:
# frozen_string_literal: truerequire"bundler/inline"gemfile(true)dosource"https://rubygems.org"git_source(:github){ |repo| "https://github.com/#{repo}.git"}gem"rails"# If you want to test against edge Rails replace the previous line with this:# gem "rails", github: "rails/rails", branch: "main"gem"sqlite3"endrequire"active_record"require"minitest/autorun"require"logger"# This connection will do for database-independent bug reports.ActiveRecord::Base.establish_connection(adapter: "sqlite3",database: ":memory:")ActiveRecord::Base.logger=Logger.new(STDOUT)ActiveRecord::Schema.definedocreate_table:posts,force: true,primary_key: %i[idaccount_id]do |t|
t.integer:idt.integer:account_idt.string:titleendcreate_table:posts_labels,force: truedo |t|
t.integer:post_idt.integer:account_idt.references:label,foreign_key: trueendcreate_table:labels,force: truedo |t|
t.string:textendendclassPost < ActiveRecord::Baseself.primary_key=%i[idaccount_id]has_many:posts_labelshas_many:labels,through: :posts_labelsendclassPostsLabel < ActiveRecord::Basebelongs_to:post,query_constraints: [:post_id,:account_id]belongs_to:labelendclassLabel < ActiveRecord::Basehas_many:posts_labelshas_many:posts,through: :posts_labelsend# Load the fixtures into the database (update the directory)ActiveRecord::FixtureSet.create_fixtures("/fixtures-directory/",%w[postslabels])classBugTest < Minitest::Testdeftest_association_stuffassert_equal1,Post.countassert_equal2,Label.countassert_equal2,Post.first.labels.count# Fails hereendend
Steps to reproduce
Copy the following fixture files in a directory:
posts.yml
labels.yml
and use them here:
Expected behavior
According to the documentation of ActiveRecord::FixtureSet, the fixture for the intermediate many-to-many table can be skipped.
Actual behavior
The fixtures are not loaded correctly. These are the sql statements for the fixtures (notice the
null
):System configuration
Rails version:
7.1.3.2
Ruby version:
3.2.2
The text was updated successfully, but these errors were encountered: