Are Transactions mandatory for obtaining the _id on Create? #2737
Unanswered
NfickettAIS
asked this question in
Q&A
Replies: 1 comment
-
Hi @NfickettAIS, the transaction is not necessary to make it work. I've just tested your code with MongoDB server 7.0 and 4.4, and Note that you don't need to specify |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
`use MongoDB\Laravel\Eloquent\Model;
class TestClass extends Model
{
protected $connection = 'mongodb';
protected $primaryKey = '_id';
protected $keyType = 'string';
}
`
Given the test model above, would it be necessary to have Transactions enabled to be able to obtain the ObjectId in the given way:
$test = new TestClass;
$test->save();
$test->refresh();
Doing this "$test->refresh()" always returns null, because the local instance ($test) cannot obtain the _id.
This may be common knowledge, but this has been driving me crazy, any help would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions