zero or one to many relationships

3 posts, 1 answers
  1. Erik
    Erik avatar
    36 posts
    Member since:
    Jun 2012

    Posted 01 Aug 2012 Link to this post

    I'm just getting started with OpenAccess ORM and I have a beginners question:

    I have 2 entities Book and Page that have a 0..1 - * relationship, so a Book can contain many Pages, and a Page can be part of 1 Book, or not be in a Book. Page has a property BookId that serves as the foreign key to the primary key column of Book.

    If I create an instance of Page, and don't provide it with a Book object, when saving changes to the database I get a constraint violated exception: page.book_id may not be NULL

    How should I model this so that I can have a Page without a Book? (e.g. keep Page.Book as null)
  2. Answer
    DuelingCats
    DuelingCats avatar
    49 posts
    Member since:
    Jul 2012

    Posted 01 Aug 2012 Link to this post

    In the entity designer, right click on your foreign key property and see if you have nullable set to true.
  3. DevCraft banner
  4. Erik
    Erik avatar
    36 posts
    Member since:
    Jun 2012

    Posted 01 Aug 2012 Link to this post

    Doh it was that simple, should have figured that one out.

    Thanks for the tip :)
Back to Top