Re: [sqlite] Only allow child record if another field in parent is false.

2014-08-02 Thread Richard Warburton
Hi, Thanks to those who gave feedback. It looks like that it will be best left to business rules. In the event that enrolmentItems are attached to leaver enrolments (due to a coding error), they will be ignored. Thanks. ___ sqlite-users mailing list s

Re: [sqlite] Only allow child record if another field in parent is false.

2014-08-01 Thread Eduardo Morras
On Fri, 1 Aug 2014 09:26:14 +1200 Richard Warburton wrote: > Hi, > > Consider: > > CREATE TABLE enrolment ( > id INTEGER PRIMARY KEY, > child INT NOT NULL REFERENCES child (id), > start INT NOT NULL, > leaver INT NOT NULL DEFAULT 0 CHECK (leaver BETWEEN 0 AND 1), -- BOOL > ); > > CR

Re: [sqlite] Only allow child record if another field in parent is false.

2014-07-31 Thread James K. Lowden
On Fri, 1 Aug 2014 09:26:14 +1200 Richard Warburton wrote: > This way, you can't change the leaver field if enrolmentItems are > attached, and you can't add an enrolmentItem if leaver is set to 1. IIUC, you have tables A and B, and the rules are you can add/delete rows in B while A.bo

Re: [sqlite] Only allow child record if another field in parent is false.

2014-07-31 Thread Simon Slavin
On 31 Jul 2014, at 10:26pm, Richard Warburton wrote: > I'm looking for an elegant way to prevent enrolments having enrolmentItems > if leaver is set to 1. > [...] > Ideally, I'd like a check in enrolmentItem that can examine a different > field in the referenced enrolment record. TRIGGERs are

[sqlite] Only allow child record if another field in parent is false.

2014-07-31 Thread Richard Warburton
Hi, Consider: CREATE TABLE enrolment ( id INTEGER PRIMARY KEY, child INT NOT NULL REFERENCES child (id), start INT NOT NULL, leaver INT NOT NULL DEFAULT 0 CHECK (leaver BETWEEN 0 AND 1), -- BOOL ); CREATE TABLE enrolmentItem ( id INTEGER PRIMARY KEY, enrolment INT NOT NULL