| 1 | <?php |
||
| 16 | trait SyncedTrait |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * If record not synced or can't be synced. Only work for PK based relations. |
||
| 20 | * |
||
| 21 | * @param RecordInterface $inner |
||
| 22 | * @param RecordInterface $outer |
||
| 23 | * |
||
| 24 | * @return bool |
||
| 25 | */ |
||
| 26 | protected function isSynced(RecordInterface $inner, RecordInterface $outer): bool |
||
| 27 | { |
||
| 28 | if (empty($inner->primaryKey()) || empty($outer->primaryKey())) { |
||
| 29 | //Parent not saved |
||
| 30 | return false; |
||
| 31 | } |
||
| 32 | |||
| 33 | //Comparing FK values |
||
| 34 | return $outer->getField( |
||
| 35 | $this->key(Record::OUTER_KEY) |
||
| 36 | ) == $inner->getField( |
||
| 37 | $this->key(Record::INNER_KEY) |
||
| 38 | ); |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Key name. |
||
| 43 | * |
||
| 44 | * @param int $key |
||
| 45 | * |
||
| 46 | * @return string|null |
||
| 47 | */ |
||
| 48 | abstract protected function key(int $key); |
||
| 49 | } |
||
| 50 |