code/Core/Extensions/DataObject.php
public function firstOrMake($filter = [], $additionalData = [], $write = true)
    {
        if (!($record = $this->owner->get()->filter($filter)->first())) {
            $record = $this->owner->create(array_merge($filter, $additionalData));

            if ($write) {
                $record->write();
                $record->isNew = true;
            }
        }

        return $record;
    }
public function firstOrMake($filter = [], $additionalData = [], $write = true)
    {
        if (!($record = $this->owner->get()->filter($filter)->first())) {
            $record = $this->owner->create(array_merge($filter, $additionalData));

            if ($write) {
                $record->write();
                $record->isNew = true;
            }
        }

        return $record;
    }
public function firstOrMake ( $ filter = [ ] , $ additionalData = [ ] , $ write = true ) { if ( ! ( $ record = $ this -> owner -> get ( ) -> filter ( $ filter ) -> first ( ) ) ) { $ record = $ this -> owner -> create ( array_merge ( $ filter , $ additionalData ) ) ; if ( $ write ) { $ record -> write ( ) ; $ record -> isNew = true ; } } return $ record ; }
Find a record using a filter, or create it if it doesn't exist

@param array $filter
@param array $additionalData
@param bool|true $write
@return static
Find a record using a filter or create it if it doesn t exist