Uploaded image for project: 'PHP ORMs'
  1. PHP ORMs
  2. PHPORM-147

Alias id to _id in the query builder

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • laravel-5.0.0
    • Affects Version/s: None
    • Component/s: Laravel
    • None
    • PHP Drivers

      By convention in Eloquent, model's primary key is id. But MongoDB uses _id as primary key (unique index automatically created and can't be removed).

       

      In order to support Laravel packages out of the box, the proposition is to modify the query builder so any query on the "id" field is converted to a query to "_id" field.

      $builder->where('id', 123)

      becomes

      { _id: 123 }

      And the same for the result. When _id is returned, the value is converted to id. This is the most tricky part as we don't want to break backward compatibility for projects that refer to _id. But this is a necessary abstraction to match Eloquent design.

      Breaking change: using an "id" field distinct from "_id" would not be supported.

      Related rejected PR:

            Assignee:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Reporter:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: