Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phalcon . How to get database name from mongoClient / service connection

I'm using Phalcon Framework with mysql and mongo database's services connection for the models of each type. We made a mongo translations system associated to the models to save related translations to mongo db, apart from mysql model information.

With a mysql model, extending \Phalcon\Mvc\Model, I can access to database's name and other information through model's associated connection service like that:

$src->getReadConnection()->getDescriptor()['dbname'];

where $src is my Phalcon\Mvc\Model

But when I try with models extending \Phalcon\Mvc\Collection, I couldn't find any way to access to the database's name. I tried to do that through phalcon\mvc\collection methods like:

Abstract class Phalcon\Mvc\Collection

public setConnectionService (unknown $connectionService)
Sets the DependencyInjection connection service name

public getConnectionService ()
Returns DependencyInjection connection service

public MongoDb getConnection ()
Retrieves a database connection

But I don't get any good way to do that. How I supposed to get that information like in \Phalcon\Mvc\Model

like image 253
Ramon Costa Avatar asked Nov 08 '22 16:11

Ramon Costa


1 Answers

You will find the method getSource() in Phalcon\Mvc\Collection, which returns the name of the collection (table name).

Your Model class should inherit from \Phalcon\Mvc\MongoCollection which inherits from Phalcon\Mvc\Collection.

EDIT: Phalcon's MongoAdapter is part of the Incubator library

like image 174
seboettg Avatar answered Nov 14 '22 21:11

seboettg