Skip to content

EmbedsMany not respecting primaryKey on association #1605

Closed
@jim5359

Description

@jim5359

I have a situation where I don't want my EmbedMany objects to have an _id attribute. Normally I can just set the $primaryKey = null on my object. But EmbedMany is not respecting this on new associations. I've identified the code that should be changed:

/Relations/EmbedsMany.php

Currently:

      protected function associateNew($model)  
      {
        // Create a new key if needed.
        if (!$model->getAttribute('_id')) {
            $model->setAttribute('_id', new ObjectID);
        }
        ...

Should Be:

    protected function associateNew($model)
    {
        // Create a new key if needed.
        if ($model->getKeyName() == '_id' && !$model->getAttribute('_id')) {
            $model->setAttribute('_id', new ObjectID);
        }
        ...

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