Sebastien
Sebastien

Reputation: 4335

One-to-one relationship with foreign key only in one table

I have 2 entities in my domain that have a one-to-one relationship with one another. Entity Business has a Promotion. And Promotion has a Business. I know this doesn't make a lot of sense and I could as well integrate the fields of Promotion into my Business entity, but I'm dealing with a legacy database here and I'm trying to model my domain on top of it without changing anything in the database for now.

My problem is that although the relationship goes both ways, it's only stored on the side of the promotion table that has a business_id foreign key, but there is no promotion_id foreign key in the business table. So when I try to run my app, Grails can't find the promotion_id column it expects to find for the promotion field in Business.

Is there any way to model my domain entity so that it understands that the column for the relationship is in the destination table only?

Upvotes: 0

Views: 129

Answers (1)

Sebastien
Sebastien

Reputation: 4335

Right after I asked this question, I found my own answer: using hasOne as explained in http://grails.org/doc/latest/ref/Domain%20Classes/hasOne.html

Upvotes: 1

Related Questions