Hei everyone
I was hoping someone would be able to help me fix this small problem I'm having. I'm trying to build a small plugin with two tables, Books and Chapters. The relation is simple; Book has many Chapters and a Chapter has one Book. The foreign key in Chapter called book_id references the id in Book. I have two different controllers on the CMS for both tables; one to add books and the other to add chapters.
The Create Books form works fine, no problem.
But when I try adding a chapter, I get a constraint failure. This seems to be because the insert query does not include the book_id, despite it appearing in the Create Chapter form. From the event log I found that the insert query looks like this:
insert into `nadja_librarian_chapters` (`ChapterName`, `ChapterNumber`, `Author`, `is_Published`, `Content`, `updated_at`, `created_at`) values (Test Chapter, 3, Test Author, 1, <p>​Stuff</p>, 2015-10-12 11:45:27, 2015-10-12 11:45:27
It clearly shows all the form elements are included, except for the relations field, book_id, although it appears just as it should as a drop down list on the page.
This is what the fields.yaml looks like:
tabs:
fields:
ChapterName:
label: Chapter Name
comment: Enter a name for the chapter.
tab: Details
ChapterNumber:
label: Chapter Number
comment: Enter the chapter number.
tab: Details
Author:
label: Author
comment: Enter the author's name.
tab: Details
Book:
label: Book
type: relation
tab: Details
options:
nameColumn: book_id
is_Published:
label: Publish
type: switch
tab: Details
Content:
label: Story
type: richeditor
size: huge
tab: Details
Does anyone know why? I've been wrestling with this for a while now and I'm running out of ideas to cycle. Any clues would be appreciated.
Last updated