Example #1
0
func testOrganismOneToOneSetOpJbrowseOrganismUsingJbrowseOrganism(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a Organism
	var b, c JbrowseOrganism

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, organismDBTypes, false, strmangle.SetComplement(organismPrimaryKeyColumns, organismColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, jbrowseOrganismDBTypes, false, strmangle.SetComplement(jbrowseOrganismPrimaryKeyColumns, jbrowseOrganismColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, jbrowseOrganismDBTypes, false, strmangle.SetComplement(jbrowseOrganismPrimaryKeyColumns, jbrowseOrganismColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*JbrowseOrganism{&b, &c} {
		err = a.SetJbrowseOrganism(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.JbrowseOrganism != x {
			t.Error("relationship struct not set to correct value")
		}
		if x.R.Organism != &a {
			t.Error("failed to append to foreign relationship struct")
		}

		if a.OrganismID != x.OrganismID {
			t.Error("foreign key was wrong value", a.OrganismID)
		}

		zero := reflect.Zero(reflect.TypeOf(x.OrganismID))
		reflect.Indirect(reflect.ValueOf(&x.OrganismID)).Set(zero)

		if err = x.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.OrganismID != x.OrganismID {
			t.Error("foreign key was wrong value", a.OrganismID, x.OrganismID)
		}

		if err = x.Delete(tx); err != nil {
			t.Fatal("failed to delete x", err)
		}
	}
}
Example #2
0
func testFeatureCvtermOneToOneSetOpFeatureCvtermPubUsingFeatureCvtermPub(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a FeatureCvterm
	var b, c FeatureCvtermPub

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, featureCvtermDBTypes, false, strmangle.SetComplement(featureCvtermPrimaryKeyColumns, featureCvtermColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, featureCvtermPubDBTypes, false, strmangle.SetComplement(featureCvtermPubPrimaryKeyColumns, featureCvtermPubColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, featureCvtermPubDBTypes, false, strmangle.SetComplement(featureCvtermPubPrimaryKeyColumns, featureCvtermPubColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*FeatureCvtermPub{&b, &c} {
		err = a.SetFeatureCvtermPub(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.FeatureCvtermPub != x {
			t.Error("relationship struct not set to correct value")
		}
		if x.R.FeatureCvterm != &a {
			t.Error("failed to append to foreign relationship struct")
		}

		if a.FeatureCvtermID != x.FeatureCvtermID {
			t.Error("foreign key was wrong value", a.FeatureCvtermID)
		}

		zero := reflect.Zero(reflect.TypeOf(x.FeatureCvtermID))
		reflect.Indirect(reflect.ValueOf(&x.FeatureCvtermID)).Set(zero)

		if err = x.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.FeatureCvtermID != x.FeatureCvtermID {
			t.Error("foreign key was wrong value", a.FeatureCvtermID, x.FeatureCvtermID)
		}

		if err = x.Delete(tx); err != nil {
			t.Fatal("failed to delete x", err)
		}
	}
}
Example #3
0
func testStockDbxrefOneToOneSetOpStockDbxrefpropUsingStockDbxrefprop(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a StockDbxref
	var b, c StockDbxrefprop

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, stockDbxrefDBTypes, false, strmangle.SetComplement(stockDbxrefPrimaryKeyColumns, stockDbxrefColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, stockDbxrefpropDBTypes, false, strmangle.SetComplement(stockDbxrefpropPrimaryKeyColumns, stockDbxrefpropColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, stockDbxrefpropDBTypes, false, strmangle.SetComplement(stockDbxrefpropPrimaryKeyColumns, stockDbxrefpropColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*StockDbxrefprop{&b, &c} {
		err = a.SetStockDbxrefprop(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.StockDbxrefprop != x {
			t.Error("relationship struct not set to correct value")
		}
		if x.R.StockDbxref != &a {
			t.Error("failed to append to foreign relationship struct")
		}

		if a.StockDbxrefID != x.StockDbxrefID {
			t.Error("foreign key was wrong value", a.StockDbxrefID)
		}

		zero := reflect.Zero(reflect.TypeOf(x.StockDbxrefID))
		reflect.Indirect(reflect.ValueOf(&x.StockDbxrefID)).Set(zero)

		if err = x.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.StockDbxrefID != x.StockDbxrefID {
			t.Error("foreign key was wrong value", a.StockDbxrefID, x.StockDbxrefID)
		}

		if err = x.Delete(tx); err != nil {
			t.Fatal("failed to delete x", err)
		}
	}
}
Example #4
0
func testAuthRoleOneToOneSetOpAuthRolePermissionUsingAuthRolePermission(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a AuthRole
	var b, c AuthRolePermission

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, authRoleDBTypes, false, strmangle.SetComplement(authRolePrimaryKeyColumns, authRoleColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, authRolePermissionDBTypes, false, strmangle.SetComplement(authRolePermissionPrimaryKeyColumns, authRolePermissionColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, authRolePermissionDBTypes, false, strmangle.SetComplement(authRolePermissionPrimaryKeyColumns, authRolePermissionColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*AuthRolePermission{&b, &c} {
		err = a.SetAuthRolePermission(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.AuthRolePermission != x {
			t.Error("relationship struct not set to correct value")
		}
		if x.R.AuthRole != &a {
			t.Error("failed to append to foreign relationship struct")
		}

		if a.AuthRoleID != x.AuthRoleID {
			t.Error("foreign key was wrong value", a.AuthRoleID)
		}

		zero := reflect.Zero(reflect.TypeOf(x.AuthRoleID))
		reflect.Indirect(reflect.ValueOf(&x.AuthRoleID)).Set(zero)

		if err = x.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.AuthRoleID != x.AuthRoleID {
			t.Error("foreign key was wrong value", a.AuthRoleID, x.AuthRoleID)
		}

		if err = x.Delete(tx); err != nil {
			t.Fatal("failed to delete x", err)
		}
	}
}
Example #5
0
func testGenotypeOneToOneSetOpPhenstatementUsingPhenstatement(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a Genotype
	var b, c Phenstatement

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, genotypeDBTypes, false, strmangle.SetComplement(genotypePrimaryKeyColumns, genotypeColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, phenstatementDBTypes, false, strmangle.SetComplement(phenstatementPrimaryKeyColumns, phenstatementColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, phenstatementDBTypes, false, strmangle.SetComplement(phenstatementPrimaryKeyColumns, phenstatementColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*Phenstatement{&b, &c} {
		err = a.SetPhenstatement(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.Phenstatement != x {
			t.Error("relationship struct not set to correct value")
		}
		if x.R.Genotype != &a {
			t.Error("failed to append to foreign relationship struct")
		}

		if a.GenotypeID != x.GenotypeID {
			t.Error("foreign key was wrong value", a.GenotypeID)
		}

		zero := reflect.Zero(reflect.TypeOf(x.GenotypeID))
		reflect.Indirect(reflect.ValueOf(&x.GenotypeID)).Set(zero)

		if err = x.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.GenotypeID != x.GenotypeID {
			t.Error("foreign key was wrong value", a.GenotypeID, x.GenotypeID)
		}

		if err = x.Delete(tx); err != nil {
			t.Fatal("failed to delete x", err)
		}
	}
}
func testFeatureGenotypeToOneSetOpFeatureUsingChromosome(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a FeatureGenotype
	var b, c Feature

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, featureGenotypeDBTypes, false, strmangle.SetComplement(featureGenotypePrimaryKeyColumns, featureGenotypeColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, featureDBTypes, false, strmangle.SetComplement(featurePrimaryKeyColumns, featureColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, featureDBTypes, false, strmangle.SetComplement(featurePrimaryKeyColumns, featureColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*Feature{&b, &c} {
		err = a.SetChromosome(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.Chromosome != x {
			t.Error("relationship struct not set to correct value")
		}

		if x.R.ChromosomeFeatureGenotype != &a {
			t.Error("failed to append to foreign relationship struct")
		}
		if a.ChromosomeID.Int != x.FeatureID {
			t.Error("foreign key was wrong value", a.ChromosomeID.Int)
		}

		zero := reflect.Zero(reflect.TypeOf(a.ChromosomeID.Int))
		reflect.Indirect(reflect.ValueOf(&a.ChromosomeID.Int)).Set(zero)

		if err = a.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.ChromosomeID.Int != x.FeatureID {
			t.Error("foreign key was wrong value", a.ChromosomeID.Int, x.FeatureID)
		}
	}
}
Example #7
0
func testPubauthorToOneSetOpPubUsingPub(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a Pubauthor
	var b, c Pub

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, pubauthorDBTypes, false, strmangle.SetComplement(pubauthorPrimaryKeyColumns, pubauthorColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, pubDBTypes, false, strmangle.SetComplement(pubPrimaryKeyColumns, pubColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, pubDBTypes, false, strmangle.SetComplement(pubPrimaryKeyColumns, pubColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*Pub{&b, &c} {
		err = a.SetPub(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.Pub != x {
			t.Error("relationship struct not set to correct value")
		}

		if x.R.Pubauthor != &a {
			t.Error("failed to append to foreign relationship struct")
		}
		if a.PubID != x.PubID {
			t.Error("foreign key was wrong value", a.PubID)
		}

		zero := reflect.Zero(reflect.TypeOf(a.PubID))
		reflect.Indirect(reflect.ValueOf(&a.PubID)).Set(zero)

		if err = a.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.PubID != x.PubID {
			t.Error("foreign key was wrong value", a.PubID, x.PubID)
		}
	}
}
func testPhenotypeComparisonToOneSetOpPhenotypeUsingPhenotype2(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a PhenotypeComparison
	var b, c Phenotype

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, phenotypeComparisonDBTypes, false, strmangle.SetComplement(phenotypeComparisonPrimaryKeyColumns, phenotypeComparisonColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, phenotypeDBTypes, false, strmangle.SetComplement(phenotypePrimaryKeyColumns, phenotypeColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, phenotypeDBTypes, false, strmangle.SetComplement(phenotypePrimaryKeyColumns, phenotypeColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*Phenotype{&b, &c} {
		err = a.SetPhenotype2(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.Phenotype2 != x {
			t.Error("relationship struct not set to correct value")
		}

		if x.R.Phenotype2PhenotypeComparisons[0] != &a {
			t.Error("failed to append to foreign relationship struct")
		}
		if a.Phenotype2ID.Int != x.PhenotypeID {
			t.Error("foreign key was wrong value", a.Phenotype2ID.Int)
		}

		zero := reflect.Zero(reflect.TypeOf(a.Phenotype2ID.Int))
		reflect.Indirect(reflect.ValueOf(&a.Phenotype2ID.Int)).Set(zero)

		if err = a.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.Phenotype2ID.Int != x.PhenotypeID {
			t.Error("foreign key was wrong value", a.Phenotype2ID.Int, x.PhenotypeID)
		}
	}
}
func testEnvironmentCvtermToOneSetOpEnvironmentUsingEnvironment(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a EnvironmentCvterm
	var b, c Environment

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, environmentCvtermDBTypes, false, strmangle.SetComplement(environmentCvtermPrimaryKeyColumns, environmentCvtermColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, environmentDBTypes, false, strmangle.SetComplement(environmentPrimaryKeyColumns, environmentColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, environmentDBTypes, false, strmangle.SetComplement(environmentPrimaryKeyColumns, environmentColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*Environment{&b, &c} {
		err = a.SetEnvironment(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.Environment != x {
			t.Error("relationship struct not set to correct value")
		}

		if x.R.EnvironmentCvterm != &a {
			t.Error("failed to append to foreign relationship struct")
		}
		if a.EnvironmentID != x.EnvironmentID {
			t.Error("foreign key was wrong value", a.EnvironmentID)
		}

		zero := reflect.Zero(reflect.TypeOf(a.EnvironmentID))
		reflect.Indirect(reflect.ValueOf(&a.EnvironmentID)).Set(zero)

		if err = a.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.EnvironmentID != x.EnvironmentID {
			t.Error("foreign key was wrong value", a.EnvironmentID, x.EnvironmentID)
		}
	}
}
func testContactRelationshipToOneSetOpContactUsingSubject(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a ContactRelationship
	var b, c Contact

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, contactRelationshipDBTypes, false, strmangle.SetComplement(contactRelationshipPrimaryKeyColumns, contactRelationshipColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, contactDBTypes, false, strmangle.SetComplement(contactPrimaryKeyColumns, contactColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, contactDBTypes, false, strmangle.SetComplement(contactPrimaryKeyColumns, contactColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*Contact{&b, &c} {
		err = a.SetSubject(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.Subject != x {
			t.Error("relationship struct not set to correct value")
		}

		if x.R.SubjectContactRelationship != &a {
			t.Error("failed to append to foreign relationship struct")
		}
		if a.SubjectID != x.ContactID {
			t.Error("foreign key was wrong value", a.SubjectID)
		}

		zero := reflect.Zero(reflect.TypeOf(a.SubjectID))
		reflect.Indirect(reflect.ValueOf(&a.SubjectID)).Set(zero)

		if err = a.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.SubjectID != x.ContactID {
			t.Error("foreign key was wrong value", a.SubjectID, x.ContactID)
		}
	}
}
func testStockItemOrderToOneSetOpStockUsingItem(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a StockItemOrder
	var b, c Stock

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, stockItemOrderDBTypes, false, strmangle.SetComplement(stockItemOrderPrimaryKeyColumns, stockItemOrderColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, stockDBTypes, false, strmangle.SetComplement(stockPrimaryKeyColumns, stockColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, stockDBTypes, false, strmangle.SetComplement(stockPrimaryKeyColumns, stockColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*Stock{&b, &c} {
		err = a.SetItem(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.Item != x {
			t.Error("relationship struct not set to correct value")
		}

		if x.R.ItemStockItemOrder != &a {
			t.Error("failed to append to foreign relationship struct")
		}
		if a.ItemID != x.StockID {
			t.Error("foreign key was wrong value", a.ItemID)
		}

		zero := reflect.Zero(reflect.TypeOf(a.ItemID))
		reflect.Indirect(reflect.ValueOf(&a.ItemID)).Set(zero)

		if err = a.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.ItemID != x.StockID {
			t.Error("foreign key was wrong value", a.ItemID, x.StockID)
		}
	}
}
Example #12
0
func testThumbnailToOneSetOpFileUsingFile(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a Thumbnail
	var b, c File

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, thumbnailDBTypes, false, strmangle.SetComplement(thumbnailPrimaryKeyColumns, thumbnailColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, fileDBTypes, false, strmangle.SetComplement(filePrimaryKeyColumns, fileColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, fileDBTypes, false, strmangle.SetComplement(filePrimaryKeyColumns, fileColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*File{&b, &c} {
		err = a.SetFile(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.File != x {
			t.Error("relationship struct not set to correct value")
		}

		if x.R.Thumbnails[0] != &a {
			t.Error("failed to append to foreign relationship struct")
		}
		if a.FileID != x.ID {
			t.Error("foreign key was wrong value", a.FileID)
		}

		zero := reflect.Zero(reflect.TypeOf(a.FileID))
		reflect.Indirect(reflect.ValueOf(&a.FileID)).Set(zero)

		if err = a.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.FileID != x.ID {
			t.Error("foreign key was wrong value", a.FileID, x.ID)
		}
	}
}
func testAnalysisfeaturepropToOneSetOpAnalysisfeatureUsingAnalysisfeature(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a Analysisfeatureprop
	var b, c Analysisfeature

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, analysisfeaturepropDBTypes, false, strmangle.SetComplement(analysisfeaturepropPrimaryKeyColumns, analysisfeaturepropColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, analysisfeatureDBTypes, false, strmangle.SetComplement(analysisfeaturePrimaryKeyColumns, analysisfeatureColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, analysisfeatureDBTypes, false, strmangle.SetComplement(analysisfeaturePrimaryKeyColumns, analysisfeatureColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*Analysisfeature{&b, &c} {
		err = a.SetAnalysisfeature(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.Analysisfeature != x {
			t.Error("relationship struct not set to correct value")
		}

		if x.R.Analysisfeatureprop != &a {
			t.Error("failed to append to foreign relationship struct")
		}
		if a.AnalysisfeatureID != x.AnalysisfeatureID {
			t.Error("foreign key was wrong value", a.AnalysisfeatureID)
		}

		zero := reflect.Zero(reflect.TypeOf(a.AnalysisfeatureID))
		reflect.Indirect(reflect.ValueOf(&a.AnalysisfeatureID)).Set(zero)

		if err = a.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.AnalysisfeatureID != x.AnalysisfeatureID {
			t.Error("foreign key was wrong value", a.AnalysisfeatureID, x.AnalysisfeatureID)
		}
	}
}
Example #14
0
func testCvtermpathToOneSetOpCvtermUsingType(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a Cvtermpath
	var b, c Cvterm

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, cvtermpathDBTypes, false, strmangle.SetComplement(cvtermpathPrimaryKeyColumns, cvtermpathColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, cvtermDBTypes, false, strmangle.SetComplement(cvtermPrimaryKeyColumns, cvtermColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, cvtermDBTypes, false, strmangle.SetComplement(cvtermPrimaryKeyColumns, cvtermColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*Cvterm{&b, &c} {
		err = a.SetType(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.Type != x {
			t.Error("relationship struct not set to correct value")
		}

		if x.R.TypeCvtermpath != &a {
			t.Error("failed to append to foreign relationship struct")
		}
		if a.TypeID.Int != x.CvtermID {
			t.Error("foreign key was wrong value", a.TypeID.Int)
		}

		zero := reflect.Zero(reflect.TypeOf(a.TypeID.Int))
		reflect.Indirect(reflect.ValueOf(&a.TypeID.Int)).Set(zero)

		if err = a.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.TypeID.Int != x.CvtermID {
			t.Error("foreign key was wrong value", a.TypeID.Int, x.CvtermID)
		}
	}
}
Example #15
0
func testOrganismDbxrefToOneSetOpDbxrefUsingDbxref(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a OrganismDbxref
	var b, c Dbxref

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, organismDbxrefDBTypes, false, strmangle.SetComplement(organismDbxrefPrimaryKeyColumns, organismDbxrefColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, dbxrefDBTypes, false, strmangle.SetComplement(dbxrefPrimaryKeyColumns, dbxrefColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &c, dbxrefDBTypes, false, strmangle.SetComplement(dbxrefPrimaryKeyColumns, dbxrefColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}

	for i, x := range []*Dbxref{&b, &c} {
		err = a.SetDbxref(tx, i != 0, x)
		if err != nil {
			t.Fatal(err)
		}

		if a.R.Dbxref != x {
			t.Error("relationship struct not set to correct value")
		}

		if x.R.OrganismDbxref != &a {
			t.Error("failed to append to foreign relationship struct")
		}
		if a.DbxrefID != x.DbxrefID {
			t.Error("foreign key was wrong value", a.DbxrefID)
		}

		zero := reflect.Zero(reflect.TypeOf(a.DbxrefID))
		reflect.Indirect(reflect.ValueOf(&a.DbxrefID)).Set(zero)

		if err = a.Reload(tx); err != nil {
			t.Fatal("failed to reload", err)
		}

		if a.DbxrefID != x.DbxrefID {
			t.Error("foreign key was wrong value", a.DbxrefID, x.DbxrefID)
		}
	}
}
Example #16
0
func testCvtermpathToOneRemoveOpCvtermUsingType(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a Cvtermpath
	var b Cvterm

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, cvtermpathDBTypes, false, strmangle.SetComplement(cvtermpathPrimaryKeyColumns, cvtermpathColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, cvtermDBTypes, false, strmangle.SetComplement(cvtermPrimaryKeyColumns, cvtermColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err = a.Insert(tx); err != nil {
		t.Fatal(err)
	}

	if err = a.SetType(tx, true, &b); err != nil {
		t.Fatal(err)
	}

	if err = a.RemoveType(tx, &b); err != nil {
		t.Error("failed to remove relationship")
	}

	count, err := a.Type(tx).Count()
	if err != nil {
		t.Error(err)
	}
	if count != 0 {
		t.Error("want no relationships remaining")
	}

	if a.R.Type != nil {
		t.Error("R struct entry should be nil")
	}

	if a.TypeID.Valid {
		t.Error("foreign key value should be nil")
	}

	if b.R.TypeCvtermpath != nil {
		t.Error("failed to remove a from b's relationships")
	}

}
func testFeatureGenotypeToOneRemoveOpFeatureUsingChromosome(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a FeatureGenotype
	var b Feature

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, featureGenotypeDBTypes, false, strmangle.SetComplement(featureGenotypePrimaryKeyColumns, featureGenotypeColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, featureDBTypes, false, strmangle.SetComplement(featurePrimaryKeyColumns, featureColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err = a.Insert(tx); err != nil {
		t.Fatal(err)
	}

	if err = a.SetChromosome(tx, true, &b); err != nil {
		t.Fatal(err)
	}

	if err = a.RemoveChromosome(tx, &b); err != nil {
		t.Error("failed to remove relationship")
	}

	count, err := a.Chromosome(tx).Count()
	if err != nil {
		t.Error(err)
	}
	if count != 0 {
		t.Error("want no relationships remaining")
	}

	if a.R.Chromosome != nil {
		t.Error("R struct entry should be nil")
	}

	if a.ChromosomeID.Valid {
		t.Error("foreign key value should be nil")
	}

	if b.R.ChromosomeFeatureGenotype != nil {
		t.Error("failed to remove a from b's relationships")
	}

}
func testPhenotypeComparisonToOneRemoveOpPhenotypeUsingPhenotype2(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a PhenotypeComparison
	var b Phenotype

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, phenotypeComparisonDBTypes, false, strmangle.SetComplement(phenotypeComparisonPrimaryKeyColumns, phenotypeComparisonColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, phenotypeDBTypes, false, strmangle.SetComplement(phenotypePrimaryKeyColumns, phenotypeColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err = a.Insert(tx); err != nil {
		t.Fatal(err)
	}

	if err = a.SetPhenotype2(tx, true, &b); err != nil {
		t.Fatal(err)
	}

	if err = a.RemovePhenotype2(tx, &b); err != nil {
		t.Error("failed to remove relationship")
	}

	count, err := a.Phenotype2(tx).Count()
	if err != nil {
		t.Error(err)
	}
	if count != 0 {
		t.Error("want no relationships remaining")
	}

	if a.R.Phenotype2 != nil {
		t.Error("R struct entry should be nil")
	}

	if a.Phenotype2ID.Valid {
		t.Error("foreign key value should be nil")
	}

	if len(b.R.Phenotype2PhenotypeComparisons) != 0 {
		t.Error("failed to remove a from b's relationships")
	}
}
func testStockRelationshipCvtermToOneRemoveOpPubUsingPub(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a StockRelationshipCvterm
	var b Pub

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, stockRelationshipCvtermDBTypes, false, strmangle.SetComplement(stockRelationshipCvtermPrimaryKeyColumns, stockRelationshipCvtermColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, pubDBTypes, false, strmangle.SetComplement(pubPrimaryKeyColumns, pubColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err = a.Insert(tx); err != nil {
		t.Fatal(err)
	}

	if err = a.SetPub(tx, true, &b); err != nil {
		t.Fatal(err)
	}

	if err = a.RemovePub(tx, &b); err != nil {
		t.Error("failed to remove relationship")
	}

	count, err := a.Pub(tx).Count()
	if err != nil {
		t.Error(err)
	}
	if count != 0 {
		t.Error("want no relationships remaining")
	}

	if a.R.Pub != nil {
		t.Error("R struct entry should be nil")
	}

	if a.PubID.Valid {
		t.Error("foreign key value should be nil")
	}

	if len(b.R.StockRelationshipCvterms) != 0 {
		t.Error("failed to remove a from b's relationships")
	}
}
Example #20
0
func testOrganismOneToOneRemoveOpStockUsingStock(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a Organism
	var b Stock

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, organismDBTypes, false, strmangle.SetComplement(organismPrimaryKeyColumns, organismColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, stockDBTypes, false, strmangle.SetComplement(stockPrimaryKeyColumns, stockColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err = a.Insert(tx); err != nil {
		t.Fatal(err)
	}

	if err = a.SetStock(tx, true, &b); err != nil {
		t.Fatal(err)
	}

	if err = a.RemoveStock(tx, &b); err != nil {
		t.Error("failed to remove relationship")
	}

	count, err := a.Stock(tx).Count()
	if err != nil {
		t.Error(err)
	}
	if count != 0 {
		t.Error("want no relationships remaining")
	}

	if a.R.Stock != nil {
		t.Error("R struct entry should be nil")
	}

	if b.OrganismID.Valid {
		t.Error("foreign key column should be nil")
	}

	if b.R.Organism != nil {
		t.Error("failed to remove a from b's relationships")
	}
}
Example #21
0
func testStockcollectionToOneRemoveOpContactUsingContact(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a Stockcollection
	var b Contact

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, stockcollectionDBTypes, false, strmangle.SetComplement(stockcollectionPrimaryKeyColumns, stockcollectionColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, contactDBTypes, false, strmangle.SetComplement(contactPrimaryKeyColumns, contactColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err = a.Insert(tx); err != nil {
		t.Fatal(err)
	}

	if err = a.SetContact(tx, true, &b); err != nil {
		t.Fatal(err)
	}

	if err = a.RemoveContact(tx, &b); err != nil {
		t.Error("failed to remove relationship")
	}

	count, err := a.Contact(tx).Count()
	if err != nil {
		t.Error(err)
	}
	if count != 0 {
		t.Error("want no relationships remaining")
	}

	if a.R.Contact != nil {
		t.Error("R struct entry should be nil")
	}

	if a.ContactID.Valid {
		t.Error("foreign key value should be nil")
	}

	if len(b.R.Stockcollections) != 0 {
		t.Error("failed to remove a from b's relationships")
	}
}
Example #22
0
func testDownloadToOneRemoveOpFileUsingFile(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a Download
	var b File

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, downloadDBTypes, false, strmangle.SetComplement(downloadPrimaryKeyColumns, downloadColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	if err = randomize.Struct(seed, &b, fileDBTypes, false, strmangle.SetComplement(filePrimaryKeyColumns, fileColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}

	if err = a.Insert(tx); err != nil {
		t.Fatal(err)
	}

	if err = a.SetFile(tx, true, &b); err != nil {
		t.Fatal(err)
	}

	if err = a.RemoveFile(tx, &b); err != nil {
		t.Error("failed to remove relationship")
	}

	count, err := a.File(tx).Count()
	if err != nil {
		t.Error(err)
	}
	if count != 0 {
		t.Error("want no relationships remaining")
	}

	if a.R.File != nil {
		t.Error("R struct entry should be nil")
	}

	if a.FileID.Valid {
		t.Error("foreign key value should be nil")
	}

	if len(b.R.Downloads) != 0 {
		t.Error("failed to remove a from b's relationships")
	}
}
Example #23
0
func testPubauthorsSliceUpdateAll(t *testing.T) {
	t.Parallel()

	if len(pubauthorColumns) == len(pubauthorPrimaryKeyColumns) {
		t.Skip("Skipping table with only primary key columns")
	}

	seed := randomize.NewSeed()
	var err error
	pubauthor := &Pubauthor{}
	if err = randomize.Struct(seed, pubauthor, pubauthorDBTypes, true); err != nil {
		t.Errorf("Unable to randomize Pubauthor struct: %s", err)
	}

	tx := MustTx(boil.Begin())
	defer tx.Rollback()
	if err = pubauthor.Insert(tx); err != nil {
		t.Error(err)
	}

	count, err := Pubauthors(tx).Count()
	if err != nil {
		t.Error(err)
	}

	if count != 1 {
		t.Error("want one record, got:", count)
	}

	if err = randomize.Struct(seed, pubauthor, pubauthorDBTypes, true, pubauthorPrimaryKeyColumns...); err != nil {
		t.Errorf("Unable to randomize Pubauthor struct: %s", err)
	}

	// Remove Primary keys and unique columns from what we plan to update
	var fields []string
	if strmangle.StringSliceMatch(pubauthorColumns, pubauthorPrimaryKeyColumns) {
		fields = pubauthorColumns
	} else {
		fields = strmangle.SetComplement(
			pubauthorColumns,
			pubauthorPrimaryKeyColumns,
		)
	}

	value := reflect.Indirect(reflect.ValueOf(pubauthor))
	updateMap := M{}
	for _, col := range fields {
		updateMap[col] = value.FieldByName(strmangle.TitleCase(col)).Interface()
	}

	slice := PubauthorSlice{pubauthor}
	if err = slice.UpdateAll(tx, updateMap); err != nil {
		t.Error(err)
	}
}
Example #24
0
func testContactToManySetOpStockcollections(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a Contact
	var b, c, d, e Stockcollection

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, contactDBTypes, false, strmangle.SetComplement(contactPrimaryKeyColumns, contactColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Stockcollection{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, stockcollectionDBTypes, false, strmangle.SetComplement(stockcollectionPrimaryKeyColumns, stockcollectionColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err = a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(tx); err != nil {
		t.Fatal(err)
	}

	err = a.SetStockcollections(tx, false, &b, &c)
	if err != nil {
		t.Fatal(err)
	}

	count, err := a.Stockcollections(tx).Count()
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	err = a.SetStockcollections(tx, true, &d, &e)
	if err != nil {
		t.Fatal(err)
	}

	count, err = a.Stockcollections(tx).Count()
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	if b.ContactID.Valid {
		t.Error("want b's foreign key value to be nil")
	}
	if c.ContactID.Valid {
		t.Error("want c's foreign key value to be nil")
	}
	if a.ContactID != d.ContactID.Int {
		t.Error("foreign key was wrong value", a.ContactID, d.ContactID.Int)
	}
	if a.ContactID != e.ContactID.Int {
		t.Error("foreign key was wrong value", a.ContactID, e.ContactID.Int)
	}

	if b.R.Contact != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if c.R.Contact != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if d.R.Contact != &a {
		t.Error("relationship was not added properly to the foreign struct")
	}
	if e.R.Contact != &a {
		t.Error("relationship was not added properly to the foreign struct")
	}

	if a.R.Stockcollections[0] != &d {
		t.Error("relationship struct slice not set to correct value")
	}
	if a.R.Stockcollections[1] != &e {
		t.Error("relationship struct slice not set to correct value")
	}
}
Example #25
0
func testFileToManySetOpDownloads(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a File
	var b, c, d, e Download

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, fileDBTypes, false, strmangle.SetComplement(filePrimaryKeyColumns, fileColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Download{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, downloadDBTypes, false, strmangle.SetComplement(downloadPrimaryKeyColumns, downloadColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err = a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(tx); err != nil {
		t.Fatal(err)
	}

	err = a.SetDownloads(tx, false, &b, &c)
	if err != nil {
		t.Fatal(err)
	}

	count, err := a.Downloads(tx).Count()
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	err = a.SetDownloads(tx, true, &d, &e)
	if err != nil {
		t.Fatal(err)
	}

	count, err = a.Downloads(tx).Count()
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	if b.FileID.Valid {
		t.Error("want b's foreign key value to be nil")
	}
	if c.FileID.Valid {
		t.Error("want c's foreign key value to be nil")
	}
	if a.ID != d.FileID.String {
		t.Error("foreign key was wrong value", a.ID, d.FileID.String)
	}
	if a.ID != e.FileID.String {
		t.Error("foreign key was wrong value", a.ID, e.FileID.String)
	}

	if b.R.File != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if c.R.File != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if d.R.File != &a {
		t.Error("relationship was not added properly to the foreign struct")
	}
	if e.R.File != &a {
		t.Error("relationship was not added properly to the foreign struct")
	}

	if a.R.Downloads[0] != &d {
		t.Error("relationship struct slice not set to correct value")
	}
	if a.R.Downloads[1] != &e {
		t.Error("relationship struct slice not set to correct value")
	}
}
Example #26
0
func testContactToManyRemoveOpStockcollections(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a Contact
	var b, c, d, e Stockcollection

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, contactDBTypes, false, strmangle.SetComplement(contactPrimaryKeyColumns, contactColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*Stockcollection{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, stockcollectionDBTypes, false, strmangle.SetComplement(stockcollectionPrimaryKeyColumns, stockcollectionColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}

	err = a.AddStockcollections(tx, true, foreigners...)
	if err != nil {
		t.Fatal(err)
	}

	count, err := a.Stockcollections(tx).Count()
	if err != nil {
		t.Fatal(err)
	}
	if count != 4 {
		t.Error("count was wrong:", count)
	}

	err = a.RemoveStockcollections(tx, foreigners[:2]...)
	if err != nil {
		t.Fatal(err)
	}

	count, err = a.Stockcollections(tx).Count()
	if err != nil {
		t.Fatal(err)
	}
	if count != 2 {
		t.Error("count was wrong:", count)
	}

	if b.ContactID.Valid {
		t.Error("want b's foreign key value to be nil")
	}
	if c.ContactID.Valid {
		t.Error("want c's foreign key value to be nil")
	}

	if b.R.Contact != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if c.R.Contact != nil {
		t.Error("relationship was not removed properly from the foreign struct")
	}
	if d.R.Contact != &a {
		t.Error("relationship to a should have been preserved")
	}
	if e.R.Contact != &a {
		t.Error("relationship to a should have been preserved")
	}

	if len(a.R.Stockcollections) != 2 {
		t.Error("should have preserved two relationships")
	}

	// Removal doesn't do a stable deletion for performance so we have to flip the order
	if a.R.Stockcollections[1] != &d {
		t.Error("relationship to d should have been preserved")
	}
	if a.R.Stockcollections[0] != &e {
		t.Error("relationship to e should have been preserved")
	}
}
Example #27
0
func testAuthProviderToManyAddOpAuthUserProviders(t *testing.T) {
	var err error

	tx := MustTx(boil.Begin())
	defer tx.Rollback()

	var a AuthProvider
	var b, c, d, e AuthUserProvider

	seed := randomize.NewSeed()
	if err = randomize.Struct(seed, &a, authProviderDBTypes, false, strmangle.SetComplement(authProviderPrimaryKeyColumns, authProviderColumnsWithoutDefault)...); err != nil {
		t.Fatal(err)
	}
	foreigners := []*AuthUserProvider{&b, &c, &d, &e}
	for _, x := range foreigners {
		if err = randomize.Struct(seed, x, authUserProviderDBTypes, false, strmangle.SetComplement(authUserProviderPrimaryKeyColumns, authUserProviderColumnsWithoutDefault)...); err != nil {
			t.Fatal(err)
		}
	}

	if err := a.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = b.Insert(tx); err != nil {
		t.Fatal(err)
	}
	if err = c.Insert(tx); err != nil {
		t.Fatal(err)
	}

	foreignersSplitByInsertion := [][]*AuthUserProvider{
		{&b, &c},
		{&d, &e},
	}

	for i, x := range foreignersSplitByInsertion {
		err = a.AddAuthUserProviders(tx, i != 0, x...)
		if err != nil {
			t.Fatal(err)
		}

		first := x[0]
		second := x[1]

		if a.AuthProviderID != first.AuthProviderID {
			t.Error("foreign key was wrong value", a.AuthProviderID, first.AuthProviderID)
		}
		if a.AuthProviderID != second.AuthProviderID {
			t.Error("foreign key was wrong value", a.AuthProviderID, second.AuthProviderID)
		}

		if first.R.AuthProvider != &a {
			t.Error("relationship was not added properly to the foreign slice")
		}
		if second.R.AuthProvider != &a {
			t.Error("relationship was not added properly to the foreign slice")
		}

		if a.R.AuthUserProviders[i*2] != first {
			t.Error("relationship struct slice not set to correct value")
		}
		if a.R.AuthUserProviders[i*2+1] != second {
			t.Error("relationship struct slice not set to correct value")
		}

		count, err := a.AuthUserProviders(tx).Count()
		if err != nil {
			t.Fatal(err)
		}
		if want := int64((i + 1) * 2); count != want {
			t.Error("want", want, "got", count)
		}
	}
}