推进多个数据库建模 [英] Propel Multiple Database Modeling

查看:177
本文介绍了推进多个数据库建模的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用Propel,我喜欢它,但是我有一个关于如何利用多个数据库连接的问题。我知道我可以在我的架构中设置连接到多个不同的数据库,但我很好奇如何处理这个代码。

I've just started working with Propel and I love it, but I have a question regarding how to utilize multiple database connections. I know I can set stuff up in my schema to connect to multiple different databases, but I'm curious how to handle this in code.

我的问题是多重数据库,每个都有略微不同的模式,没有数据仓库。因此,我的东西类似于以下内容:

The issue I have is multiple databases, and each of them has slightly different schemas with no data warehousing. As a result I have things resembling the following:

databaseName: westCoastUsers
table: users
column1: email
column2: password
column3: FirstName

databaseName: eastCoastUsers
table: users
column1: email
column2: password
column3: firstName
column4: lastName

现在在PHP非Propel版本中,我手动完成所有操作,并根据需要手动切换数据库。我希望简化一些事情,我很好奇如何建模这个。有没有办法我可以有东西像东方的服务器和westCoastUser模型,每个都引用适当的数据库/ etc或我试图楔入不支持的东西?

Right now in PHP non-Propel version, I'm doing all this by hand, and switching databases manually as required. I'm hoping to streamline things a bit, and I'm curious how to model this. Is there a way I can just have something like eastCoastUser and westCoastUser models that each refer to the proper database/etc or am I trying to wedge in something not supported?

我阅读:如何在推进中使用两个数据库,但不确定如何

I read this: How to use two database in propel but am uncertain how to actually execute that in code.

感谢您的帮助

推荐答案

在模式文件中,您可以为代表表的类提供一个名称。他们不必使用与表相同的名称。您可以使用表元素上的 phpName 属性来执行此操作。

In your schema files, you can provide a name for the class that represents your table. They do not have to use the same name as the table. You do this with the phpName attribute on the table element.

例如,您的schema.xml可能包含这个

For example your schema.xml could contain something like this

<database name="westCoastUsers">
  <table name="users" phpName="WestCoastUser">
    ...columns here...
  </table>
  ...
</database>
<database name="eastCoastUsers">
  <table name="users" phpName="EastCoastUser">
    ...columns here...
  </table>
</database>

(编辑,请注意, name =westCoastUser数据库元素是指数据库的名称,而不是具有相似名称的类)

(edit, note that the name="westCoastUser" on the database element refers to the name of the database, not the classes with similar names)

然后在构建时,propel将生成 WestCoastUser WestCoastUserQuery WestCoastUserPeer EastCoastUser EastCoastUserQuery EastCoastUserPeer 。每个类都将使用您在架构中定义的数据库进行连接。

Then at build time, propel will generate WestCoastUser, WestCoastUserQuery, WestCoastUserPeer, EastCoastUser, EastCoastUserQuery and, EastCoastUserPeer. Each class will connect using the database it was defined under in your schema.

这篇关于推进多个数据库建模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆