Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

fORMSchema::retrieve($class) ?

posted by mattsah 8 years ago

Looking into multiple databases I was curious as to what fORMSchema would do with regards to retrieving the schema of particular databases and I noted that the documentation (as far as code examples go) is fairly limited, but the API does reference that you can pass a class, with which the schema will be "used with."

My understanding of this is likely that it would look for a class to database mapping and retrieve the schema of that database, but since the schema object returned is on the database, wouldn't it make more sense to have the database name as set up with fORMDatabase::attach() used instead of a class?

I guess this is partially a "ticket" of some sorts, but perhaps I'm missing something and I'm just misunderstanding. It would seem, for example, a bit backwards for me to have to think of a random class on a database in order to do something like this:

fORMSchema::retrieve('classOnOtherDB')->getTables();

vs.

fORMSchema::retrieve('other_db')->getTables();

The purpose of fORMSchema::retrieve() is to retrieve the fSchema for use with fActiveRecord. Thus, instead of having to look up what database an fActiveRecord class is in and pass it to fORMSchema::retrieve(), you simply pass the class name. Since any related class must be in the same database, the schema object will give you access to all related classes/tables also.

posted by wbond 8 years ago

If this is the case, is there any way to easily determine all tables across only attached databases?

This is kind of my point with regards to using the fActiveRecord class name... if I am just trying to get a list of tables across all attached databases I now have to pick a random fActiveRecord for each attached database which has been mapped to that database in order to get tables.

This is similarly constrained with fORMDatabase::retrieve().

In short, assuming I know my attached database names but perhaps don't have any class to database mappings yet, or perhaps not even any fActiveRecords at all, but I just want a list of tables on each...any way to do this at all?

posted by mattsah 8 years ago

No there isn't. In fact, there isn't even a way to get a list of all database names.

It sounds to me like you need a totally different mechanism for the management of named databases.

posted by wbond 8 years ago

I'm assuming you're talking about the attached names and not the actual database names. I did notice the fSchema also has the getDatabases() method, but that appears to be all databases across the server:

[/var/www/dotink.org/inkwell/includes]# print_r(fORMSchema::retrieve()->getDatabases());
Array
(
    [0] => inkwelldemo_dotink_org
    [1] => jackshighwayrc_org
    [2] => kmw
    [3] => postgres
    [4] => redmine_default
    [5] => template0
    [6] => template1
)

It seems the only way I could likely do this is to keep independent track of the fDatabase objects by their attached names, and then manually create fSchema objects per those fDatabase objects. Well, back to the drawing board there. Much appreciated.

posted by mattsah 8 years ago