Skip to content

Commit

Permalink
Merge branch '3.x' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
octoberapp committed Sep 7, 2023
2 parents c495714 + f49276d commit 8ed5765
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/Database/Relations/DeferOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function withDeferred($sessionKey = null)
}

// Bind (Add)
$query = $query->orWhereIn($this->getWithDeferredQualifiedKeyName(), function ($query) use ($sessionKey) {
$query = $query->orWhereIn($this->related->getQualifiedKeyName(), function ($query) use ($sessionKey) {
$query
->select('slave_id')
->from('deferred_bindings')
Expand All @@ -79,7 +79,7 @@ public function withDeferred($sessionKey = null)
});

// Unbind (Remove)
$newQuery->whereNotIn($this->getWithDeferredQualifiedKeyName(), function ($query) use ($sessionKey) {
$newQuery->whereNotIn($this->related->getQualifiedKeyName(), function ($query) use ($sessionKey) {
$query
->select('slave_id')
->from('deferred_bindings')
Expand Down
16 changes: 8 additions & 8 deletions src/Database/Traits/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ protected function getRelationValidationValue($relationName)
!$this->relationLoaded($relationName) &&
$this->hasDeferred($this->sessionKey, $relationName)
) {
$fetchMethod = $this->isRelationTypeSingular($relationName) ? 'first' : 'get';
$data = $this->$relationName()->withDeferred($this->sessionKey)->$fetchMethod();
$data = $this->$relationName()->withDeferred($this->sessionKey)->get();
}
else {
$data = $this->$relationName;
Expand Down Expand Up @@ -194,12 +193,7 @@ protected function getRelationValidationValue($relationName)
return $value;
};

// Process singular
if ($this->isRelationTypeSingular($relationName)) {
return $processValidationValue($data);
}

// Process multi
// Cast to primitive type
if ($data instanceof \Illuminate\Support\Collection) {
$data = $data->all();
}
Expand All @@ -208,6 +202,12 @@ protected function getRelationValidationValue($relationName)
return null;
}

// Process singular (last item)
if ($this->isRelationTypeSingular($relationName)) {
return $processValidationValue($data[array_key_last($data)]);
}

// Process multi
$result = [];

foreach ($data as $key => $value) {
Expand Down
8 changes: 3 additions & 5 deletions src/Parse/Syntax/SyntaxModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function defineSyntaxRelations()
}

/**
* Prepare the syntax field data for saving.
* getFormSyntaxData prepares the syntax field data for saving.
*/
public function getFormSyntaxData()
{
Expand All @@ -57,9 +57,7 @@ public function getFormSyntaxData()
continue;
}

/*
* File upload
*/
// File upload
if ($params['type'] === 'fileupload' && $this->hasRelation($field)) {
if ($this->sessionKey) {
if ($image = $this->$field()->withDeferred($this->sessionKey)->first()) {
Expand All @@ -79,7 +77,7 @@ public function getFormSyntaxData()
}

/**
* Helper to get the perfect sized image.
* getThumbForImage helper to get the perfect sized image.
*/
protected function getThumbForImage($image, $params = [])
{
Expand Down

0 comments on commit 8ed5765

Please sign in to comment.