Skip to content

Many to many, can't get related objects #75

Closed
@rcwsr

Description

@rcwsr

I'm implementing a many to many relationship between two models, User and Club. The documentation says "The belongsToMany relation will not use a pivot "table", but will push id's to a related_ids attribute instead.".

However, I've set up belongsToMany on both models, and when attaching or syncing, a pivot table is created named, for example. user_club. I can even specify the name of the pivot-table in my models, as well as pass extra attributes to store in the pivot-table when syncing or or attaching. When creating the relationship, nothing is stored Is this expected behavior?

If it is, then I'm having trouble getting related items. For example, I'm trying to display all the users that belong to a club with $users = $club->users();. But in a var_dump, I can't see anything related to users. Am I doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions