Details
Description
This issue is a lot like the bug with refreshRelated() in ticket #DC-93. Calling save() on a record will cause hasOne rows to be generated in error (with all NULL values). It looks the saveRelatedLocalKeys function checks for foreign keys, calls isModified, which returns true, and calls save on that related object. isModified is returning true for a row that doesn't exist.
schema.yml
---
Staff:
columns:
username: string(50)
password: string(255)
active:
type: boolean
default: true
indexes:
user_pass_active_idx:
fields: [username, password, active]
Tickets:
columns:
mask:
unique: true
type: string(10)
staff_id: integer(9)
relations:
Staff:
local: staff_id
foreign: id
test.php
<?php $ticket = new Tickets(); $ticket->staff = null; // This save generates the NULL record in the staff table $ticket->save();
Hi, this patch is not valid. We can't only save records that already exist. That means it stops all new records from being saved. If you want to help fix this, first we'll need a reproducible test case. Thanks, Jon