Recess Developer Forums: Table prfix - Recess Developer Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Table prfix

#1 User is offline   Daniel Icon

  • Group: Members
  • Posts: 11
  • Joined: 08-March 10

Posted 08 March 2010 - 07:13 AM

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".
0

#2 User is offline   Thomaz Icon

  • Group: Members
  • Posts: 39
  • Joined: 28-August 09
  • LocationHeemskerk, The Netherlands

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...
Hoppa
0

#3 User is offline   Daniel Icon

  • Group: Members
  • Posts: 11
  • Joined: 08-March 10

Posted 08 March 2010 - 11:13 AM

View PostThomaz, 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...

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.
0

#4 User is offline   Thomaz Icon

  • Group: Members
  • Posts: 39
  • Joined: 28-August 09
  • LocationHeemskerk, The Netherlands

Posted 08 March 2010 - 11:37 AM

View PostDaniel, 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.


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 :P
Hoppa
0

#5 User is offline   Daniel Icon

  • Group: Members
  • Posts: 11
  • Joined: 08-March 10

Posted 08 March 2010 - 06:29 PM

View PostThomaz, on 08 March 2010 - 05:37 PM, said:

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 :P

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. ;)
0

#6 User is offline   Thomaz Icon

  • Group: Members
  • Posts: 39
  • Joined: 28-August 09
  • LocationHeemskerk, The Netherlands

Posted 09 March 2010 - 03:49 AM

View PostDaniel, 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
0

#7 User is offline   Daniel Icon

  • Group: Members
  • Posts: 11
  • Joined: 08-March 10

Posted 09 March 2010 - 08:48 AM

View PostThomaz, 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.. :)

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. :unsure:
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users