yiisoft / yii2-mongodb

Yii 2 MongoDB extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
326 stars 191 forks source link

`batchInsert` does not work with ActiveRecord models (probably) #293

Open ilya-realforce opened 4 years ago

ilya-realforce commented 4 years ago

Doc for \yii\mongodb\Collection::batchInsert() says @param array $rows array of arrays or objects to be inserted, but it doesn't work if you pass array of ActiveRecord into it. Probably because they fall straight into \MongoDB\Driver\BulkWrite::insert at src/Command.php:225, and ActiveRecord doesn't store any data in "real" properties, it stores it in "magic" properties.

Possible solution: use getAttributes() if objects are instances of \yii\mongodb\ActiveRecord before passing them to \MongoDB\Driver\BulkWrite::insert.