gpt4 book ai didi

php - 为什么这些不能插入多对多关系发挥作用?

转载 作者:行者123 更新时间:2023-11-29 06:57:10 25 4
gpt4 key购买 nike

我正在关注此文档:http://www.propelorm.org/documentation/04-relationships.html#manytomany_relationships

我有一个非常相似的设置(尽管为了可读性做了一些简化):

日志

  <table name="logbook" phpName="Logbook" idMethod="native">
<column name="id" phpName="Id" type="INTEGER" size="10" sqlType="int(10) unsigned" primaryKey="true" autoIncrement="true" required="true"/>
<column name="location" phpName="Location" type="VARCHAR" size="255" required="false"/>
</table>

联系方式

  <table name="contact" phpName="Contact" idMethod="native">
<column name="id" phpName="Id" type="INTEGER" size="10" sqlType="int(10) unsigned" primaryKey="true" autoIncrement="true" required="true"/>
<column name="title" phpName="Title" type="VARCHAR" size="255" required="true"/>
<column name="name" phpName="Name" type="VARCHAR" size="255" required="true"/>
<column name="telephone" phpName="Telephone" type="VARCHAR" size="20" required="true"/>
</table>

联系日志

  <table name="logbook_contact" phpName="LogbookContact" idMethod="native" isCrossRef="true">
<column name="logbook_id" phpName="LogbookId" type="INTEGER" size="10" sqlType="int(10) unsigned" primaryKey="true" required="true"/>
<column name="contact_id" phpName="ContactId" type="INTEGER" size="10" sqlType="int(10) unsigned" primaryKey="true" required="true"/>
<foreign-key foreignTable="contact" name="fk_logbook_contact_contact" onDelete="CASCADE" onUpdate="CASCADE">
<reference local="contact_id" foreign="id"/>
</foreign-key>
<foreign-key foreignTable="logbook" name="fk_logbook_contact_logbook" onDelete="CASCADE" onUpdate="CASCADE">
<reference local="logbook_id" foreign="id"/>
</foreign-key>
<index name="fk_logbook_contact_contact">
<index-column name="contact_id"/>
</index>
</table>

注意 logbook_contact 表上的 isCrossRef="true",它表明这是一个联结表。从这里我重新运行 propel-gen om 甚至 propel-gen convert-conf (在清除构建目录之后)但我似乎仍然没有能够做这样的事情:

<?php
/* presume $logbook has been LogbookQuery::create()'d already... */
$contacts = $logbook->getContacts();
$nbContacts = $logbook->countContacts();

我使用 Zend Studio,但我没有在代码提示窗口中看到它:

No $logbook->getContacts();

任何人都可以向我建议我在这里可能做错了什么吗?我很高兴你能给我指点文档——我已经尽可能密切地关注这些文档,直到 $test 工作正常。

最佳答案

您可能想在 Logbook 实例上调用 getContacts(),而不是在 PropelCollection 上调用。查看您的代码,您似乎获取了 Logbook 的集合而不是实例:

$this->logbook = $this->company->getLogbooks();

在这里,$this->logbook 似乎是关于自动完成输出的 PropelCollection。它不是 Logbook 对象。你可以试试:

$test = $this->logbook[0]->getContacts(); 

关于php - 为什么这些不能插入多对多关系发挥作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12058780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com