Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony Many-to-Many Relationship with External Database
    text
    copied!<p>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.</p> <p>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). </p> <p>Here's how I specified the relationships:</p> <pre><code>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 </code></pre> <p>When I try using the model in my application, I get this error:</p> <pre><code>Base table or view not found: 1146 Table 'uda_web_dev.message_news_rel' doesn't exist </code></pre> <p>...referring no doubt to this part of the query: </p> <pre><code>FROM news n LEFT JOIN message_news_rel </code></pre> <p>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.</p> <p>Please let me know if I left out any important details.</p> <p>Is there a known fix for this problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload