# |
Mar 29th 2019, 13:28 |
admad |
@val make your own locator class by extending core's `TableLocator`. Then use Controller::modelFactory() to set your locator as for model of type "Table" |
# |
Mar 29th 2019, 13:26 |
joopm |
but i have issue because i have an error the Call to undefined method viewBuilder |
# |
Mar 29th 2019, 13:25 |
joopm |
my component is extends from Component |
# |
Mar 29th 2019, 13:25 |
joopm |
i would like to use he viewbuilder in a component controller |
# |
Mar 29th 2019, 13:25 |
joopm |
hello there |
# |
Mar 29th 2019, 13:21 |
val |
Would it be possible to configure `TableLocator` to change `$config` params passed to `Table` constructor? |
# |
Mar 29th 2019, 13:12 |
admad |
it isn't used under actual query is generated |
# |
Mar 29th 2019, 13:12 |
admad |
you should be able to switch table name even after model is constructed |
# |
Mar 29th 2019, 13:11 |
val |
https://api.cakephp.org/3.6/class-Cake.ORM.Table.html#___construct seems to support `$config['table']` parameter |
# |
Mar 29th 2019, 13:10 |
val |
ok, that might work when the model is already constructed. how would it be possible to do something similar before the model is constructed? I mean to pass the table name to the model constructor. |
# |
Mar 29th 2019, 13:05 |
admad |
or rather getTable()/setTable() to prefix db/schema name to the table |
# |
Mar 29th 2019, 13:02 |
admad |
you can try tinkering with Table::getAlias() / setAlias() |
# |
Mar 29th 2019, 12:58 |
admad |
i can't remember off top of my head what's the method which handles that |
# |
Mar 29th 2019, 12:58 |
val |
@spriz nope, no subdomains |
# |
Mar 29th 2019, 12:58 |
admad |
@val right, you can prefix the db names to tables/aliases |
# |
Mar 29th 2019, 12:58 |
spriz |
@val do each customer not have their own subdomain or something like that? In that case you’d need to only get that single subdomain |
# |
Mar 29th 2019, 12:56 |
val |
@admad well, in cake 2.x this can be done by prefixing the table name with the schema name. F.ex. `$DataSource->buildStatement([..., 'table' => 'db_1.orders_table'], $this)`. |
# |
Mar 29th 2019, 12:49 |
admad |
yeah you can't stuff like that when using an abstraction layer |
# |
Mar 29th 2019, 12:47 |
val |
`db_main`, `db_1`, `db_2` are different databases. |
# |
Mar 29th 2019, 12:46 |
val |
A very simplified example in MySQL: `USE db_main; SELECT * from db_main.customers; SELECT * from db_1.orders_table; SELECT * from db_2.orders_table;` |
# |
Mar 29th 2019, 12:46 |
admad |
db name is specified when PDO object is created |
# |
Mar 29th 2019, 12:44 |
val |
@admad so, technically the database connection is the same, but the schema name is not |
# |
Mar 29th 2019, 12:43 |
val |
@admad iterating 1000 customers and creating 1000 connections is not viable. We do switch the schema name on the fly in 2.x but in a quite a hacky way. So, I hoped it would be easier in 3.x. |
# |
Mar 29th 2019, 12:39 |
val |
@spriz I saw that article. That would not work for us. |
# |
Mar 29th 2019, 12:39 |
admad |
if connection hasn't already been made than just update the connection config |
# |
Mar 29th 2019, 12:38 |
admad |
@val you can't change db of active connection. you need to change and reconnect so practically same as making new connection |
# |
Mar 29th 2019, 12:38 |
spriz |
It’s from 2015 but I think it’s still applicable with minor adjustments |
# |
Mar 29th 2019, 12:37 |
spriz |
I’d check http://mark-story.com/posts/view/using-cakephp-and-a-horizontally-sharded-database :slightly_smiling_face: |
# |
Mar 29th 2019, 12:37 |
val |
@spriz what simpler solution? @admad ok, how the connection can switch from one schema from another without creating a new connection? |
# |
Mar 29th 2019, 12:35 |
spriz |
I’ve previously just used multiple database connections though |
# |
Mar 29th 2019, 12:35 |
admad |
database name name is set in connection, models/tables know nothign abotu it |
# |
Mar 29th 2019, 12:35 |
spriz |
There’s been quite a lot of talk about multi tenancy applications like that in cakephp, I think there is a simpler solution to that @val :slightly_smiling_face: |
# |
Mar 29th 2019, 12:35 |
val |
@admad by scheama I mean a database with tables |
# |
Mar 29th 2019, 12:34 |
admad |
@val you by schema you mean table? |
# |
Mar 29th 2019, 12:34 |
val |
@spriz more or less the same environment. Because there are thousands of customers. @admad nope. We use MySQL. |
# |
Mar 29th 2019, 12:33 |
spriz |
And why is it too expensive to create a new connection? |
# |
Mar 29th 2019, 12:33 |
admad |
@val are you referring to postgres schema? |
# |
Mar 29th 2019, 12:33 |
spriz |
Hmm, and it’s the same app environment for all customers? |
# |
Mar 29th 2019, 12:28 |
val |
I wonder how would it be possible to set the schema name before the model is created. Logically, model factory seems to be a good place for that. |
# |
Mar 29th 2019, 12:24 |
val |
> Hi, is there a quick way in cake 3.x to switch to a different database schema without creating a new database connection? The use case is when each customer has its own database, the schemas are identical for each customer and cake app needs to retrieve data from multiple databases (from identical table of the customer database). Or simply to switch from one customer database to another. Creating new connections is too expensive. |
# |
Mar 29th 2019, 12:22 |
spriz |
What are you trying to accomplish @val? |