C
C
Casper Phantom2016-04-27 08:03:39
PHP
Casper Phantom, 2016-04-27 08:03:39

Once again about ActiveRecord vs. DataMapper, are there connections in DM?

Is it possible to make connections without using crutches in DM, as it is implemented in AR?
An example of one of the variations for AR:

public function relations()
{
    return [
         'profile' => [static::HAS_ONE, 'Profile', ['user_id'=>'id']],
         'posts' => [static::HAS_MANY, 'Posts', ['user_id'=>'user_id']]
    ];
}

and further in the code:
$user->profile->name;
$user->profile->family;

foreach ($user->posts as $post) {
    $post->name;
    $post->text;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
index0h, 2016-04-27
@index0h

doctrine-orm.readthedocs.org/projects/doctrine-orm...

T
trevoga_su, 2016-04-27
@trevoga_su

these are not crutches, but one of the approaches. nothing new has come up yet.
That's how I got around the connection problem.
The controller receives data from the mapper and throws it into the view:
https://github.com/Vasiliy-Makogon/ADV/blob/master...
view:
https://github.com/Vasiliy-Makogon/ADV/blob/master ...
Notice the $row in each iteration of the foreach. This is an array containing model objects. Model objects, not just objects.
This is how a multidimensional array of objects is returned:
https://github.com/Vasiliy-Makogon/ADV/blob/master...
-----
That is: we have, as it were, full-fledged objects and a DataMapper, but there are no connections. We write any kind of SQL and the result will be arrays of domain model objects.
I sincerely think the idea of ​​creating something that would actually work, in the style of $user->city->name, is a very non-trivial task. And unreasonably costly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question