drq1257 2010-12-06 19:59 采纳率: 0%
浏览 59
已采纳

Symfony与外部数据库的多对多关系

In my application, I need to query a table in an external database database, which is linked to my default database by a many to many relationship. My intermediate table is situated in my default database.

In order to do this, I modified my database.yml to include the external database. I then added to my schema.yml both the intermediary table (message_news_rel, situated in my default database), and the table from the external source (news).

Here's how I specified the relationships:

MessageNews:
  connection: uda_iPoste
  tableName: message_news_rel
  columns:
    message_id:
      type: integer(10)
      primary: true
    news_id:
      type: integer(10)
      primary: true
  relations:
    Message:
      local: message_id
      foreign: id
      foreignAlias: MessageNewses
    News:
      local: news_id
      foreign: id
      foreignAlias: MessageNewses

News:
...
  relations:
    Messages:
      class: Message
      foreignAlias: Newses
      refClass: MessageNews
      local: news_id
      foreign: message_id

Message:
...
  relations:
    Newses:
      class: News
      foreignAlias: Messages
      refClass: MessageNews
      local: message_id
      foreign: news_id

When I try using the model in my application, I get this error:

Base table or view not found: 1146 Table 'uda_web_dev.message_news_rel' doesn't exist

...referring no doubt to this part of the query:

FROM news n LEFT JOIN message_news_rel 

This is leaving me to assume that Symfony didn't switch the connection from my default database to my external database when attempting to make the relationship.

Please let me know if I left out any important details.

Is there a known fix for this problem?

  • 写回答

1条回答 默认 最新

  • dssk35460 2010-12-27 17:26
    关注

    If you think about it rationally, what your asking is a bit to much. Every query or transaction should involve only tables that exists on the database that your going to execute it. Dont forget that the database abstraction always has its limitations, and if you check each implementation, they abstract the query creation and manipulation, but i dont see how they cant abstract databases.

    So if you absolutely have to split your databases, then implement some kind of dabatase cluster. Else, implement tables in a query are located in the same database and then join results in symfony.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器