Skip to content

there is no need to save the ids in both collections for a belongsToMany relation, or am I wrong? #2040

Open
@elfeffe

Description

@elfeffe

I'm doing

$product = Product::where('sku', '0713XX3FF1')->where('store_id', 1)->first();
$category = Category::where('entity_id', 158)->first();
$product->categories()->attach( $category );

And this is saving the related ids on both collections, so if I have 1 category, with 10000 products, the category has an array of 10000 products inside.
What's the reason?
Saving the category inside the product will do the job, or I'm losing something?

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