Skip to content

Accessing hasMany() without foreign key #289

@mmethner

Description

@mmethner

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions