Is there a way to do it like this in Fluent, e.g. having the parent's primary key to be propagated to the child's primary key?
For those, who don't know WebObjects and the Enterprise Objects Framework (short "EOF") here is a PDF for further studies: Free Software by Pascal Bourguignon
If I understand the question (and I have no experience of WebObjects so it's highly likely!) you want to set up a foreign key constant on the child table. Which is definitely possible in Fluent, like so. That will stop you saving a child if the parent doesn't exist in the db
the example you gave me looks so different from what is detailed here: Vapor: Fluent → Overview , so at first one question: is that really Vapor 4 code or just another way to do things?
What I want to accomplish is to have referential integrity at database level: the child table should not be able to contain more than one entry for each parent table entry. When modelling this at the database level you'll propagate the primary key of the parent table to the child table as primary key (and use it as foreign key at the same time). If I understand the example you have given correctly it would indeed be possible for more than one Acronym to share the same userID since those Acronyms are identified by their id. So, theoretically, it is possible to have more than one Acronym with the same userID.
Of course there are ways to avoid such situations by handling those in the Swift code. I guess you where trying to show me such an example. But I must confess I don't see how such a situation is avoided there. This might be due to the fact that I am pretty new to Vapor (4, don't know the other versions at all) and so don't understand what is going on there (for instance, what is that:
var categories: Siblings<Acronym, Category, AcronymCategoryPivot> {
return siblings()
}
doing there? what is it for?).
I hope I explained sufficiently enough what my goal is (I am really bad at explaining, sorry).
One last thing: an unsolicited advice (I know, people hat those, but his one is here really trying to help):
If you're going to implemtent an ORM, make yourself familiar with the Enterprise Objects Framework (EOF).