yii2-mongodb icon indicating copy to clipboard operation
yii2-mongodb copied to clipboard

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

Open ilya-realforce opened this issue 5 years ago • 0 comments

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.

ilya-realforce avatar Jan 10 '20 13:01 ilya-realforce