-
Notifications
You must be signed in to change notification settings - Fork 23
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
Relationships manyToOne NULL #97
Comments
The same problem for oneToOne relationship. A track for resolution? class OneToOne extends DeletableRelationship
{
protected function stitchIntoRecord(
Record $nativeRecord,
array $foreignRecords
) : void {
$nativeRecord->{$this->name} = false;
if ($this->onDelete === static::SET_NULL) {
$nativeRecord->{$this->name} = null;
}
foreach ($foreignRecords as $foreignRecord) {
if ($this->recordsMatch($nativeRecord, $foreignRecord)) {
$nativeRecord->{$this->name} = $foreignRecord;
}
}
}
// ...
} So if reference column can be null, the value must not be false but null? |
/me ponders Can you tell me a little about the domain object that is being built from the record? |
Yes. For example: class Author
{
// ...
public function __construct(?int $author_id, ?string $name)
{
$this->author_id = $author_id;
// ...
}
}
class Thread
{
public function __construct(?int $article_id, ?string $title, ?string $content, ?Author $author)
{
$this->article_id = $article_id;
// ...
}
} And the relationships in DataSource: class AuthorRelationships extends MapperRelationships
{
protected function define()
{
$this->oneToMany('threads',
Thread::CLASS,
[
'author_id' => 'author_id',
]);
}
}
class ThreadRelationships extends MapperRelationships
{
protected function define()
{
$this->manyToOne('author',
Author::CLASS,
[
'author_id' => 'author_id',
])
->onDeleteSetNull();
}
} |
And the problem is that sometimes, when you fetch a ThreadRecord from the data source with('author'), the author field is false because there is no related author row? |
Yes is that. |
All right, I think I understand now. Some background: the The most expedient solution I can think of is to modify Atlas Transit to accept both "false" and "null" to mean "null" when the target domain property is an object. Would that work for you here? |
Yes of course, that will works for me if it's implemented in Transit. |
@ElGigi please examine atlasphp/Atlas.Transit#7 and see if it works for you! |
Hi,
I have a problem with relationships manyToOne with capacity to be null.
The relation key return FALSE if the relation is NULL. I can understand that.
But the problem, it's with Atlas.Transit, the Transit object throw an exception.
For example :
Entities:
Thread can have an author or anonymous (without author).
In the case of anonymous. The field "author" is FALSE instead NULL.
Atlas.Transit works fine with existent relation, but throw an exception if relation is NULL:
Thanks.
The text was updated successfully, but these errors were encountered: