Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCSP-41335: Id field alias #3042

Merged
merged 18 commits into from
Sep 5, 2024
Merged

Conversation

norareidy
Copy link
Contributor

@norareidy norareidy commented Jul 12, 2024

JIRA - https://jira.mongodb.org/browse/DOCSP-41335
Staging - https://preview-mongodbnorareidy.gatsbyjs.io/laravel/DOCSP-41335-id/query-builder/#logical-or-example

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file
  • Update documentation for new features

@github-actions github-actions bot added the docs label Jul 12, 2024
@norareidy norareidy changed the base branch from 4.6 to 4.7 July 15, 2024 14:24
Copy link
Contributor

@rustagir rustagir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some non blocking suggestions

Comment on lines 179 to 181
``movies`` collection that either match the ``_id``
value of ``ObjectId('573a1398f29313caabce9682')`` or match
the ``title`` value ``"Back to the Future"``:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``movies`` collection that either match the ``_id``
value of ``ObjectId('573a1398f29313caabce9682')`` or match
the ``title`` value ``"Back to the Future"``:
``movies`` collection in which the value of the``_id``
field is ``ObjectId('573a1398f29313caabce9682')`` or
the value of the ``title`` field is ``"Back to the Future"``:

Comment on lines 189 to 195
.. note::

Beginning in {+odm-short+} v5.0, you can use the ``id`` alias to
represent the ``_id`` field, as shown in the preceding code. When you
run a find operation using the query builder, {+odm-short+}
automatically converts between ``id`` and ``_id``. You cannot have
two separate ``id`` and ``_id`` fields in your documents.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: (applies when you change the target branch to 5.0) Remove versioning since this is only going to be in that version of docs anyways

Suggested change
.. note::
Beginning in {+odm-short+} v5.0, you can use the ``id`` alias to
represent the ``_id`` field, as shown in the preceding code. When you
run a find operation using the query builder, {+odm-short+}
automatically converts between ``id`` and ``_id``. You cannot have
two separate ``id`` and ``_id`` fields in your documents.
.. note::
You can use the ``id`` alias in your queries to
represent the ``_id`` field in MongoDB documents, as shown in the preceding code. When you
run a find operation using the query builder, {+odm-short+}
automatically converts between ``id`` and ``_id``. Because of this behavior,
you cannot have two separate ``id`` and ``_id`` fields in your documents.

@norareidy norareidy marked this pull request as ready for review July 16, 2024 15:48
@norareidy norareidy requested a review from a team as a code owner July 16, 2024 15:48
@norareidy norareidy requested a review from GromNaN July 16, 2024 15:49
Copy link
Contributor

@rustagir rustagir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving again to remove this from my review queue

@rustagir rustagir changed the base branch from 4.8 to 4.6 July 23, 2024 15:49
@rustagir rustagir requested a review from a team as a code owner July 23, 2024 15:49
@rustagir rustagir self-assigned this Jul 23, 2024
@rustagir rustagir marked this pull request as draft July 23, 2024 15:58
@rustagir rustagir changed the base branch from 4.6 to 4.8 July 23, 2024 15:59
@norareidy norareidy changed the base branch from 4.8 to 5.0 August 12, 2024 18:19
@GromNaN
Copy link
Member

GromNaN commented Aug 19, 2024

Setting the Model $primaryKey is no logger necessary since models using id as PK will see their requests converted to _id.

- ``$primaryKey = '_id'``, because the ``_id`` field uniquely
identifies MongoDB documents

@norareidy norareidy marked this pull request as ready for review August 30, 2024 15:15
@norareidy norareidy requested a review from a team as a code owner August 30, 2024 15:15
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little fix and good to go.

@@ -62,8 +63,8 @@ public function testOrWhere(): void
{
// begin query orWhere
$result = DB::connection('mongodb')
->table('movies')
->where('year', 1955)
->collection('movies')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
->collection('movies')
->table('movies')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make the rest of these collection -> table changes in https://jira.mongodb.org/browse/DOCSP-42956

``_id`` field in MongoDB documents, as shown in the preceding
code. When you run a find operation using the query builder, {+odm-short+}
automatically converts between ``id`` and ``_id``. Because of this behavior,
you cannot have two separate ``id`` and ``_id`` fields in your documents.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can explain that this behavior allows better compatibility with Laravel, "id" being the default name for primary keys in SQL databases.

@norareidy norareidy merged commit e424861 into mongodb:5.0 Sep 5, 2024
15 checks passed
@norareidy norareidy deleted the DOCSP-41335-id-alias branch September 5, 2024 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants