Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 48925f0

Browse files
committed
Fix broken test on references using FK attributes
1 parent d303975 commit 48925f0

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

tests/ServiceStack.OrmLite.Tests/LoadReferencesJoinTests.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,13 @@ public void Can_load_list_of_references()
553553
[Test]
554554
public void Can_join_on_references_attribute()
555555
{
556-
// Drop table 2 first because of foreign key
556+
// Drop tables in order that FK allows
557+
db.DropTable<TABLE_3>();
557558
db.DropTable<TABLE_2>();
558-
db.DropAndCreateTable<TABLE_1>();
559-
db.DropAndCreateTable<TABLE_2>();
560-
db.DropAndCreateTable<TABLE_3>();
559+
db.DropTable<TABLE_1>();
560+
db.CreateTable<TABLE_1>();
561+
db.CreateTable<TABLE_2>();
562+
db.CreateTable<TABLE_3>();
561563

562564
var id1 = db.Insert(new TABLE_1 { One = "A" }, selectIdentity: true);
563565
var id2 = db.Insert(new TABLE_1 { One = "B" }, selectIdentity: true);
@@ -571,11 +573,19 @@ public void Can_join_on_references_attribute()
571573
Assert.That(results.Count, Is.EqualTo(1));
572574
Assert.That(results[0].One, Is.EqualTo("A"));
573575

574-
var row3 = new TABLE_3 { TableTwo = new TABLE_2 {Three = "3"} };
575-
db.Save(row3);
576+
var row3 = new TABLE_3 {
577+
Three = "3a",
578+
TableTwo = new TABLE_2
579+
{
580+
Three = "3b",
581+
TableOneKey = (int)id1,
582+
}
583+
};
584+
db.Save(row3, references:true);
585+
576586
Assert.That(row3.TableTwoKey, Is.EqualTo(row3.TableTwo.Id));
577587

578-
row3 = db.SingleById<TABLE_3>(row3.Id);
588+
row3 = db.LoadSingleById<TABLE_3>(row3.Id);
579589
Assert.That(row3.TableTwoKey, Is.EqualTo(row3.TableTwo.Id));
580590
}
581591
}
@@ -617,8 +627,9 @@ public class TABLE_3 : IHasId<int>
617627
public string Three { get; set; }
618628

619629
[References(typeof(TABLE_2))]
620-
public int TableTwoKey { get; set; }
630+
public int? TableTwoKey { get; set; }
621631

632+
[Reference]
622633
public TABLE_2 TableTwo { get; set; }
623634
}
624635
}

0 commit comments

Comments
 (0)