You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
Feature Request
Is it possible to have table prefixes in the model name? Accomplishing this with the current release is done by putting individual names in the model file.
My Stack
CodeIgniter v2.1.4
php-activerecord -v0.0.2
[installed through] sparks v0.0.9
The use case
There are different domains of an enterprise application which share the same database.
For example, A company sells products handled by A company's website using the a_company database table. B company also sells products using their own website but shares database (say because of hosting restrictions) with A company. Assuming both follow the convention of naming their database models after the models—a_products and b_products, respectively—they need to differentiate their database models somehow.
This use case can be easily solved by the solution provided by the spark but assuming such similarity is not limited to one table, assuming this similarity approaches countable infinity, in such case, manually redefining names of tables in model files will not only be tedious but inefficient.
My proposal remains as above: a means to use prefixes in table names. CodeIgniter already provides a $config[database][dbprefix] = 'pfx'—the "pfx" is an assumption—option which can be used like so
`$this->db->prefix("table_name"); // should result in pfx_table_name
However, the PHPActiveRecord spark does not respect this, since…
I don't really add features to this package anymore, but I think someone just made a PR for DB prefixes which is slightly different.
It could be possible, but I'd recommend doing something like what you've done but tweaked slightly to use proper syntax. Then just extend from that base class.
classBaseModelextendsActiveRecord\Model
{
/** * Retrieves the name of the table for this Model. * * @return string */publicstaticfunctiontable_name()
{
returnget_instance()->db->prefix(static::table()->table);
}
}
This should be close to the right syntax. You can further example the Model class inside of PHPActiveRecord to verify.
Feature Request
Is it possible to have table prefixes in the model name? Accomplishing this with the current release is done by putting individual names in the model file.
My Stack
The use case
There are different domains of an enterprise application which share the same database.
For example, A company sells products handled by A company's website using the a_company database table. B company also sells products using their own website but shares database (say because of hosting restrictions) with A company. Assuming both follow the convention of naming their database models after the models—
a_products
andb_products
, respectively—they need to differentiate their database models somehow.This use case can be easily solved by the solution provided by the spark but assuming such similarity is not limited to one table, assuming this similarity approaches countable infinity, in such case, manually redefining names of tables in model files will not only be tedious but inefficient.
My proposal remains as above: a means to use prefixes in table names. CodeIgniter already provides a
$config[database][dbprefix] = 'pfx'
—the "pfx" is an assumption—option which can be used like soHowever, the PHPActiveRecord spark does not respect this, since…
… still assumes the table name is
tests
by virtue of……but in my MySQL database, there is a "pfx_tests".
The text was updated successfully, but these errors were encountered: