# Dynamic Models and WordPress MU

**URL:** <https://discuss.rubyonrails.org/t/dynamic-models-and-wordpress-mu/48344>\
**Category:** rubyonrails-talk\
**Created:** [January 4, 2010, 7:50pm UTC](https://discuss.rubyonrails.org/t/dynamic-models-and-wordpress-mu/48344 "2010-01-04T19:50:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shware11](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@shware11](https://discuss.rubyonrails.org/u/shware11)\
**Post date:** [January 4, 2010, 7:50pm UTC](https://discuss.rubyonrails.org/t/dynamic-models-and-wordpress-mu/48344/1 "2010-01-04T19:50:45Z")

</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
