Closed nohponex closed 7 years ago
@alkallio @ConsideredHarmless could we use something like a promise of ResourceModel
instead to solve this ?
The constructor of Relationship
class is:
<?php
public function __construct(
ResourceModel $model,
int $type = Relationship::TYPE_TO_ONE,
string $recordDataAttribute = null,
\stdClass $callbacks = null,
int $flags = Relationship::FLAG_DEFAULT
) {
A callable
instead of stdObject
at setRelationships(\stdClass $relationships)
should probably do the trick but it wont allow helper methods like addRelationship
or removeRelationship
to be implemented (could be used when extending an existing ResourceModel) .
Even if have something like lazy-evaluation (getRelationships calls the callable only when needed, hopefully after the construction of all ResourceModel)
So probably relationships MUST be defined separately when extending if they are different from "base" ResourceModel
At 5a6d700
<?php
->setRelationships(
(object) [
'author' => new Relationship(
function () {
return User::getResourceModel();
},
Relationship::TYPE_TO_ONE,
'creator-user_id'
),
'tag' => new Relationship(
function () {
return Tag::getResourceModel();
},
Relationship::TYPE_TO_MANY,
null,//'tag_id'
(object) [
/**
* @param string $articleId
* @return string[]
*/
'GET' => function (string $articleId) {
$ids = [];
return $ids;
}
]
)
]
);
Seems to do the trick
When having a
Article
that has atag
relationships and aTag
model that has aarticle
relationship like in https://github.com/phramework/jsonapi-exampleThe definition of
Article
class:Tag
class is similarThis is a very serious issue, since a lot of times have self referencing models (for example
parent
relationship)