-
Notifications
You must be signed in to change notification settings - Fork 821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG Renable the ability to do dynamic assignment with DBField #8821
Merged
robbieaverill
merged 3 commits into
silverstripe:3.6
from
open-sausages:pulls/3.6/restore-dynamic-field-assigment
Feb 26, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/** | ||
* This is a fake DB field specifically design to test dynamic value assignment. You can set `scalarValueOnly` in | ||
* the constructor. You can control whetever the field will try to do a dynamic assignment by specifing | ||
* `$dynamicAssignment` in nthe consturctor. | ||
* | ||
* If the field is set to false, it will try to do a plain assignment. This is so you can save the initial value no | ||
* matter what. If the field is set to true, it will try to do a dynamic assignment. | ||
*/ | ||
class MockDynamicAssignmentDBField extends Boolean | ||
{ | ||
|
||
private $scalarOnly; | ||
private $dynamicAssignment; | ||
|
||
/** | ||
* @param string $name | ||
* @param boolean $scalarOnly Whether our fake field should be scalar only. | ||
* @param boolean $dynamicAssignment Whether our fake field will try to do a dynamic assignment. | ||
*/ | ||
public function __construct($name = '', $scalarOnly = false, $dynamicAssignment = false) | ||
{ | ||
$this->scalarOnly = $scalarOnly; | ||
$this->dynamicAssignment = $dynamicAssignment; | ||
parent::__construct($name); | ||
} | ||
|
||
/** | ||
* If the field value and dynamicAssignment are true, we'll try to do a dynamic assignment | ||
* @param mixed $value | ||
* @return array|int|mixed | ||
*/ | ||
public function prepValueForDB($value) | ||
{ | ||
if ($value) { | ||
return $this->dynamicAssignment | ||
? array('ABS(?)' => array(1)) | ||
: 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
public function scalarValueOnly() | ||
{ | ||
return $this->scalarOnly; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* This is a fake DB field specifically design to test dynamic value assignment | ||
* @property boolean $StaticScalarOnlyField | ||
* @property boolean $DynamicScalarOnlyField | ||
* @property boolean $DynamicField | ||
* @method ManyManyList MockManyMany | ||
*/ | ||
class MockDynamicAssignmentDataObject extends DataObject implements TestOnly | ||
{ | ||
|
||
private static $db = array( | ||
// This field only emits scalar value and will save | ||
'StaticScalarOnlyField' => 'MockDynamicAssignmentDBField(1,0)', | ||
|
||
// This field tries to emit dynamic assignment but will fail because of scalar only | ||
'DynamicScalarOnlyField' => 'MockDynamicAssignmentDBField(1,1)', | ||
|
||
// This field does dynamic assignment and will pass | ||
'DynamicField' => 'MockDynamicAssignmentDBField(0,1)', | ||
); | ||
|
||
private static $many_many = array( | ||
"MockManyMany" => 'MockDynamicAssignmentDataObject' | ||
); | ||
|
||
private static $belongs_many_many = array( | ||
"MockBelongsManyMany" => 'MockDynamicAssignmentDataObject' | ||
); | ||
|
||
private static $many_many_extraFields = array( | ||
'MockManyMany' => array( | ||
// This field only emits scalar value and will save | ||
'ManyManyStaticScalarOnlyField' => 'MockDynamicAssignmentDBField(1,0)', | ||
|
||
// This field tries to emit dynamic assignment but will fail because of scalar only | ||
'ManyManyDynamicScalarOnlyField' => 'MockDynamicAssignmentDBField(1,1)', | ||
|
||
// This field does dynamic assignment and will pass | ||
'ManyManyDynamicField' => 'MockDynamicAssignmentDBField(0,1)', | ||
) | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah - user errors 😆