Hi there. For me it's common to use table prefixes since i'm using a lot of hosting environments where you only get 1 or 2 databases. So how would i use table prefixes in Recess? I can't have variables in a model's !Table annotation, can i?
Cheers
Daniel
Edit: typo in the topic. Should be "prefix".
Page 1 of 1
Table prfix
#2
Posted 08 March 2010 - 08:52 AM
Perhaps you can add another line of code to your {myapp}Application.class.php (something like $this->tablePrefix = 'bleh') and have TableAnnotation (/recess/recess/database/orm/annotations) read out this property.
But this means tinkering around with the Recess internals, and requires TableAnnotation to look in your Application class, which isn't static so it should be able to access the instance of your Application, requiring some nasty global $application; line or something else. (Haven't tried it myself, but I think this isn't one of the best solutions and it would be much of a difference compared to just edit the Model...)
But then again, you want to use a single Recess app on multiple servers with different database layouts? Because I don't get it exactly...
But this means tinkering around with the Recess internals, and requires TableAnnotation to look in your Application class, which isn't static so it should be able to access the instance of your Application, requiring some nasty global $application; line or something else. (Haven't tried it myself, but I think this isn't one of the best solutions and it would be much of a difference compared to just edit the Model...)
But then again, you want to use a single Recess app on multiple servers with different database layouts? Because I don't get it exactly...
Hoppa
#3
Posted 08 March 2010 - 11:13 AM
Thomaz, on 08 March 2010 - 02:52 PM, said:
Perhaps you can add another line of code to your {myapp}Application.class.php (something like $this->tablePrefix = 'bleh') and have TableAnnotation (/recess/recess/database/orm/annotations) read out this property.
But this means tinkering around with the Recess internals, and requires TableAnnotation to look in your Application class, which isn't static so it should be able to access the instance of your Application, requiring some nasty global $application; line or something else. (Haven't tried it myself, but I think this isn't one of the best solutions and it would be much of a difference compared to just edit the Model...)
But then again, you want to use a single Recess app on multiple servers with different database layouts? Because I don't get it exactly...
But this means tinkering around with the Recess internals, and requires TableAnnotation to look in your Application class, which isn't static so it should be able to access the instance of your Application, requiring some nasty global $application; line or something else. (Haven't tried it myself, but I think this isn't one of the best solutions and it would be much of a difference compared to just edit the Model...)
But then again, you want to use a single Recess app on multiple servers with different database layouts? Because I don't get it exactly...
Yes, that wouldn't be a nice solution for the reasons you mentioned. But i think i'll have a look into it.
What i'm trying to achieve is using one database (schema) for multiple applications and having a prefix on your table names makes it easier to grasp which table belongs to which app.
#4
Posted 08 March 2010 - 11:37 AM
Daniel, on 08 March 2010 - 06:13 PM, said:
Yes, that wouldn't be a nice solution for the reasons you mentioned. But i think i'll have a look into it.
What i'm trying to achieve is using one database (schema) for multiple applications and having a prefix on your table names makes it easier to grasp which table belongs to which app.
What i'm trying to achieve is using one database (schema) for multiple applications and having a prefix on your table names makes it easier to grasp which table belongs to which app.
Yes, but that is easily done by specifying the right table for a Model. With this:
/**
* !Database Default
* !Table {prefix}_{table}
*/
class MyTable extends Model { [..] }
you can specify a table for your Model and keep the Model's name tidy and small. (ie model name: User and table name: reallyuglyandlongprefix_usertableofthisandthat)
Or is this not what you mean
Hoppa
#5
Posted 08 March 2010 - 06:29 PM
Thomaz, on 08 March 2010 - 05:37 PM, said:
Yes, but that is easily done by specifying the right table for a Model. With this:
you can specify a table for your Model and keep the Model's name tidy and small. (ie model name: User and table name: reallyuglyandlongprefix_usertableofthisandthat)
Or is this not what you mean
/**
* !Database Default
* !Table {prefix}_{table}
*/
class MyTable extends Model { [..] }
you can specify a table for your Model and keep the Model's name tidy and small. (ie model name: User and table name: reallyuglyandlongprefix_usertableofthisandthat)
Or is this not what you mean
Sure, that's how i'm doing it currently. But it would be nice if i could specify the prefix in one place so i don't have to edit all model files. Guess i'm just a lazy bastard.
#6
Posted 09 March 2010 - 03:49 AM
Daniel, on 09 March 2010 - 01:29 AM, said:
Sure, that's how i'm doing it currently. But it would be nice if i could specify the prefix in one place so i don't have to edit all model files. Guess i'm just a lazy bastard. 
What you could do is add all your different databases to the RecessConf::$namedDatabases in recess-conf.php. And then somehow introduce a way to define a global table prefix (in those database configurations), and then you only need to have your Models choose the correct database (* !Database {dbname}) and edit the * !Table Annotation in such a way that it combines the given table name with the global table prefix.
I think this makes more sense..
Hoppa
#7
Posted 09 March 2010 - 08:48 AM
Thomaz, on 09 March 2010 - 09:49 AM, said:
What you could do is add all your different databases to the RecessConf::$namedDatabases in recess-conf.php. And then somehow introduce a way to define a global table prefix (in those database configurations), and then you only need to have your Models choose the correct database (* !Database {dbname}) and edit the * !Table Annotation in such a way that it combines the given table name with the global table prefix.
I think this makes more sense..
I think this makes more sense..
Well, like i said, i only got one DB and putting the table prefix into recess-conf.php would mean, that i have to define all those prefixes for all apps there. That's because i need prefixes on a "per-app" basis. So to me it seems better to have that switch in my *Application.class.php file along with all the other prefixes, like you suggested before. The DB configs aren't really aware of which apps are using them (so to say), are they? So i think i'll go down that route for now and see where i'll end up.
Page 1 of 1

Sign In
Register
Help

MultiQuote