# Dynamic Models and WordPress MU

**URL:** <https://www.ruby-forum.com/t/dynamic-models-and-wordpress-mu/181071>\
**Category:** Rails\
**Created:** [January 5, 2010, 1:14am UTC](https://www.ruby-forum.com/t/dynamic-models-and-wordpress-mu/181071 "2010-01-05T01:14:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shware1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f04885/32.png) [@shware1](https://www.ruby-forum.com/u/shware1)\
**Post date:** [January 5, 2010, 1:14am UTC](https://www.ruby-forum.com/t/dynamic-models-and-wordpress-mu/181071/1 "2010-01-05T01:14:56Z")

</div>

Hi,

WordPress is a PHP-based blogging engine. The MU version supports  
multiple blogs in the same database (as opposed to just one in the  
basic WordPress app) I’m looking at writing some Rails-based admin  
modules to interact with WordPress MU.

WordPress MU creates a separate set of tables for each blog. It does  
this by using a master wp\_blogs table and for each blog it creates a  
set of tables named like:

wp\_nn\_posts  
wp\_nn\_comments

The “nn” is the record id from the wp\_blogs tables. So blog id of 1  
generates:

wp\_1\_posts  
wp\_1\_comments

What would be the best way to reference these models through  
ActiveRecord?

Would it be as simple as creating 1 base set of models and then using  
Model.table\_name = “wp\_1\_posts” to point to the right tables when the  
admin module is accessed? Is the table\_name attribute safe to play  
with in a multi-user environment? Is another way better suited to  
this kind of access?

There are more tables than indicated above, I’m trying to keep this  
post short 🙂 We’re looking at potentially hosting 100’s of blogs so  
I don’t think we want to create a distinct set of models for each.

Thanks for any advice,

Shawn

–

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).
