| | 133 | |
|---|
| | 134 | |
|---|
| | 135 | # ---------------------------------------------------------------- |
|---|
| | 136 | |
|---|
| | 137 | |
|---|
| | 138 | class Bamc(E.Entity): |
|---|
| | 139 | """Bamc and Batc circularly reference eachother. |
|---|
| | 140 | |
|---|
| | 141 | The relationships created upon a creation of a Bamc entity |
|---|
| | 142 | can be visualized as follows:: |
|---|
| | 143 | |
|---|
| | 144 | .-----------------. |
|---|
| | 145 | | Bamc[1] |<----. |
|---|
| | 146 | | | | |
|---|
| | 147 | .-------.batc = Batc[1] | | CASCADE |
|---|
| | 148 | | `-----------------` | |
|---|
| | 149 | RESTRICT | | |
|---|
| | 150 | | .-----------------. | |
|---|
| | 151 | `---->| Batc[1] | | |
|---|
| | 152 | | | | |
|---|
| | 153 | | .bamc = Bamc[1]-------` |
|---|
| | 154 | `-----------------` |
|---|
| | 155 | """ |
|---|
| | 156 | |
|---|
| | 157 | batc = f.entity('Batc') |
|---|
| | 158 | |
|---|
| | 159 | class _Create(T.Create): |
|---|
| | 160 | |
|---|
| | 161 | def _setup(self): |
|---|
| | 162 | # We assign this internally. |
|---|
| | 163 | del self.f.batc |
|---|
| | 164 | |
|---|
| | 165 | def _after_execute(self, db, bamc): |
|---|
| | 166 | create = db.Batc.t.create |
|---|
| | 167 | # Every bamc has one batc. |
|---|
| | 168 | batc = db.execute(create(bamc=bamc)) |
|---|
| | 169 | db.execute(bamc.t.update(batc=batc)) |
|---|
| | 170 | |
|---|
| | 171 | |
|---|
| | 172 | class Batc(E.Entity): |
|---|
| | 173 | |
|---|
| | 174 | bamc = f.entity('Bamc', on_delete=CASCADE) |
|---|