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

MongoDB support

Open samuelrajan747 opened this issue 2 months ago • 4 comments

Need support for

  • transactions
  • record helpers (haveRecord)

looks like we have to effectively copy paste the entire bunch of record helpers and swap the active record refence to mimic. and for transaction, both connection watcher and transaction forcer is hard refenced to yii/db/Connection, to have transaction support we have to clone them and swap references to yii/mongodb/Connection and yii/mongodb/Transaction.

@samdark - Ideally, can we have a common parent for both yii/db/Connection and yii/mongodb/Connection? something like yii/db/BaseConnection.

Thanks

samuelrajan747 avatar Nov 19 '25 06:11 samuelrajan747

I'm not using MondoDB myself, so unlikely that I'll do it. If you have any idea on how to implement it, go ahead.

samdark avatar Nov 19 '25 06:11 samdark

I'm happy to do it as long as you give your thumbs up. My question here is more on is it ok to have a yii/db/BaseConnection and yii/db/BaseTransaction? like we have for active record?

samuelrajan747 avatar Nov 20 '25 08:11 samuelrajan747

It's better to have interfaces.

samdark avatar Nov 20 '25 18:11 samdark

I think the record helpers will already work. The mongo AR model extends BaseActiveRecord, which implements ActiveRecordInterface. So we can have the helpers use that as a typehint.

For transactions I'd just do adapt the existing listener to also listen to mongodb connection class, if it exists.

SamMousa avatar Nov 20 '25 20:11 SamMousa