public function sync($attributes)
    {
        if (isset($attributes['$id'])) {
            $this->state = static::STATE_ATTACHED;
            $this->id = $attributes['$id'];
        } else {
            foreach ($this->schema() as $key => $field) {
                if ($field->has('default')) {
                    $attributes[$key] = $field['default'];
                }
            }

            $this->state = static::STATE_DETACHED;
        }

        $this->set($attributes);
        $this->populateOld();
    }