spotorm / spot2

Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer
http://phpdatamapper.com
BSD 3-Clause "New" or "Revised" License
601 stars 101 forks source link

Accessing hasMany() without foreign key #289

Open mmethner opened 5 years ago

mmethner commented 5 years ago

Hello, I know the way how to use hasMany() if there is a database relation like

table articles \Entity\Articles
articles.id = 1
articles.text = ...

table comments \Entity\Comments
comments.id= 2
comments.article_id = 1
comments.text = ...

Accessing it, would look like this.

$mapper->hasMany(
            $entity,
                '\Entity\Comments',
                'article_id'
            ),

What I want to do is, accessing the related table through a member of the original table (not through a mapping table with HasManyThrough()). So the layout looks like this:

table articles \Entity\Articles
articles.id = 1
**articles.comment_ids = '["1","6"]'**
articles.text = ...

table comments \Entity\Comments
comments.id= 2
comments.text = ...

Is this possible? So the final target is to access the relation through the common public static function relations() method in the Entity class.

FlipEverything commented 5 years ago

Unfortunately I don't know the answer to that, but I don't think so....