-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW Allow a single has_one to manage multiple reciprocal has_many
- Loading branch information
1 parent
809f9e7
commit d400125
Showing
24 changed files
with
806 additions
and
94 deletions.
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
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
38 changes: 38 additions & 0 deletions
38
src/ORM/FieldType/DBPolymorphicRelationAwareForeignKey.php
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,38 @@ | ||
<?php | ||
|
||
namespace SilverStripe\ORM\FieldType; | ||
|
||
use InvalidArgumentException; | ||
use SilverStripe\ORM\DataObject; | ||
|
||
/** | ||
* A special polymorphic ForeignKey class that allows a single has_one relation to map to multiple has_many relations | ||
*/ | ||
class DBPolymorphicRelationAwareForeignKey extends DBPolymorphicForeignKey | ||
{ | ||
private static array $composite_db = [ | ||
'Relation' => 'Varchar', | ||
]; | ||
|
||
/** | ||
* Get the value of the "Relation" this key points to | ||
* | ||
* @return string Name of the has_many relation being stored | ||
*/ | ||
public function getRelationValue(): string | ||
{ | ||
return $this->getField('Relation'); | ||
} | ||
|
||
/** | ||
* Set the value of the "Relation" this key points to | ||
* | ||
* @param string $value Name of the has_many relation being stored | ||
* @param bool $markChanged Mark this field as changed? | ||
*/ | ||
public function setRelationValue(string $value, bool $markChanged = true): static | ||
{ | ||
$this->setField('Relation', $value, $markChanged); | ||
return $this; | ||
} | ||
} |
Oops, something went wrong.