I have 2 objects, ObjectA
and ObjectB
.
When ObjectA
gets created, ObjectB
doesn't (and can't, due to not having the data yet) exist yet.
Once ObjectB
is created, it needs to have a corresponding ObjectA
attached to it if an appropriate one exists. If there isn't an appropriate ObjectA
, then the new ObjectB
simply isn't connected to one.
So, all ObjectA
instances will eventually be attached to an ObjectB
, but not all ObjectB
instances will have an ObjectA
.
Essentially, I'm looking for GORM to build database tables like this:
ObjectA
- Id (NotNull, unique)
- ObjectB_Id[FK: ObjectB.Id] (unique)
ObjectB
- Id (NotNull, unique)
How can I put together the GORM domain classes to do this?
I've tried just about every combination of hasOne
, belongsTo
, raw properties, nullable: true
and unique: true
constraints I can think of, but I must be missing one. This doesn't seem like it's a particularly odd scenario, so there must be some way to accomplish this.