Dynamic table names in Doctrine - doctrine

If I have tables in doctrine for user_1, user_2, etc. is there a way to dynamically set the table name in Doctrine for a single User model?
It's weird, I know. I'm trying to create an interface to a WordPress database (because WP has little to no API for directly accessing posts), and WP creates duplicate tables for each site, so there's a wp_posts, wp_comments, wp_2_posts, wp_2_comments, etc.

Here's what I ended up doing:
$post = new WordPressPost();
$post->setTableName('wp_'.$user_id.'_posts');

If it could, you would have to run migrations for each added/deleted user.
I am curious; why would you EVER need something like that?

I don't know how WP works, but here is the thing; each site should use it's OWN database, not to share it with others.

Related

How to create Laravel model from migration?

I found many results how to create migration from a model, but is there any way to create a model from migrations?
Basically I want to give a table name, and if there is multiple migration files (one to create and others to update the previous states) the model could be updated.
Is there any solution for this?
I'm not sure that there's a good way to create a model directly from migrations, as it depends on what database you use as to the exact structure of your tables.
There seems to be a package which support generating the models from your database, however:
https://github.com/laracademy/generators

Postgres ActiveRecord limit table size to one row

I am creating a custom CMS using Sinatra and Postgres with sinatra-activerecord enabled. I am creating a model called SiteInfo which will store information such as the about_description, about_photo, tagline, etc. Is there a way within the migration to create that SiteInfo table to specify that there can only be one row? There's no way through the interface for the admin or user to create an additional one, I'm just wondering.
To answer your question: No, you can't, and there is no need for.
You'll want to do something like SiteInfo.first to load your information anyway.

Joomla: regenerate aliases for all articles at once?

I am working on a Joomla 3.2.1 site and the client, without thinking, entered in the same alias for all articles, instead of letting the system use the article title. So now if I want to turn on SEF URL's we are going to have 404 issues in the future.
I want to resave or regenerate all article aliases at once (batch).
Is there a way to do it? in the MYSQL DB maybe?
Thank you in advance.
$alias = JApplication::stringURLSafe($article->title);
Joomla will generate the alias when saving the article. I am not aware of any batch joomla feature to regenerate all the aliases and I would also be interested to know about this.
If no other batch solution exists, you should do manually the updates to these fields.
In the database, you could run update queries for all your articles, but you must type each update query one by one.
The update query for a single row would look like:
UPDATE jos_content
SET alias='my-new-alias-name'
WHERE id='{id-of-the-article}'
For multiple rows at once, you could do something like this:
UPDATE jos_content
SET alias = CASE id
WHEN 1 THEN 'alias1'
WHEN 2 THEN 'alias2'
WHEN 3 THEN 'alias3'
END
WHERE id IN (1,2,3)
What you could do is delete the alias data from all of your articles in the database using mysql. Then make a tag, like "fixalias." Using the batch processing feature tag all of the articles with that tag.
This will run store() for all of your articles and automatically generate the aliases. Then delete the tag from the tag manager.you ar
A similar strategy would involve also deleting all the aliases but batch moving (don't copy) your articles to a temporary category and then moving them back.

Model with multiple tables

We run two websites, A and B. Each website has its own table, _a_ and _b_ which have exactly the same structure. Yes, I know it's silly, we'll be rewriting them over the course of this year and next.
Using Laravel I need to create a model that will hold both tables content. I don't need any kind of UPDATE or INSERT functionality, I just need to SELECT and use with to access other model information.
Is this possible with Laravel 4.1? I can individually model each table, but that would make it difficult in the future.
I was able to fix this by making using the Repository pattern and merging the results of each model into the get and all functions.

Getting a dbid by table name

As far as I know, all QuickBase API calls are called using the following syntax: http://<quickbase>/db/<dbid>?
Is there a way to get the dbid field without navigating to that database table within QuickBase?
If the above is not possible, would anyone recommend anything other than creating another table that stores the IDs of the tables you want?
With the latter method, I believe I would only need to store one dbid and could pull down the rest (which I believe would still need to be user entered, but would be better than requiring them to change the code).
Thanks for the help!
API_GetSchema will return the list of dbids.
https://www.quickbase.com/db/<yourApplicationId>?act=API_GetSchema&apptoken=<yourApplicationTokenId>&fmt=flat

Resources