我有这 2 个类,它们之间有 ManyToMany 关联:
Nursery.php
namespace VS\CrmBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Nursery
*
* @ORM\Table(name="Nursery")
* @ORM\Entity(repositoryClass="VS\CrmBundle\Repository\NurseryRepository")
*/
class Nursery
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=100)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="phone_number", type="string", length=15, nullable=true)
*/
private $phoneNumber;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @var Address
*
* @ORM\OneToOne(targetEntity="Address", inversedBy="nursery", cascade={"persist"})
* @ORM\JoinColumn(name="fk_address_id", referencedColumnName="id")
*/
private $address;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="Staff", mappedBy="nurseries", cascade={"persist"})
*/
private $staff;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Schedule", mappedBy="nursery", cascade={"persist"})
*/
private $schedule;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Contact", mappedBy="nursery", cascade={"persist"})
*/
private $contacts;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="RegisterRecord", mappedBy="nursery", cascade={"persist"})
*/
private $registerRecords;
/**
* Nursery constructor.
*/
public function __construct()
{
$this->staff = new ArrayCollection();
$this->schedule = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->contacts = new ArrayCollection();
$this->registerRecord = new ArrayCollection();
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Nursery
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set phoneNumber
*
* @param string $phoneNumber
*
* @return Nursery
*/
public function setPhoneNumber($phoneNumber)
{
$this->phoneNumber = $phoneNumber;
return $this;
}
/**
* Get phoneNumber
*
* @return string
*/
public function getPhoneNumber()
{
return $this->phoneNumber;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
*
* @return Nursery
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
*
* @return Nursery
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set address
*
* @param \VS\CrmBundle\Entity\Address $address
*
* @return Nursery
*/
public function setAddress(\VS\CrmBundle\Entity\Address $address = null)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* @return \VS\CrmBundle\Entity\Address
*/
public function getAddress()
{
return $this->address;
}
/**
* Add staff
*
* @param \VS\CrmBundle\Entity\Staff $staff
*
* @return Nursery
*/
public function addStaff(\VS\CrmBundle\Entity\Staff $staff)
{
$this->staff[] = $staff;
return $this;
}
/**
* Remove staff
*
* @param \VS\CrmBundle\Entity\Staff $staff
*/
public function removeStaff(\VS\CrmBundle\Entity\Staff $staff)
{
$this->staff->removeElement($staff);
}
/**
* Get staff
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getStaff()
{
return $this->staff;
}
/**
* Add schedule
*
* @param \VS\CrmBundle\Entity\Schedule $schedule
*
* @return Nursery
*/
public function addSchedule(\VS\CrmBundle\Entity\Schedule $schedule)
{
$this->schedule[] = $schedule;
return $this;
}
/**
* Remove schedule
*
* @param \VS\CrmBundle\Entity\Schedule $schedule
*/
public function removeSchedule(\VS\CrmBundle\Entity\Schedule $schedule)
{
$this->schedule->removeElement($schedule);
}
/**
* Get schedule
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getSchedule()
{
return $this->schedule;
}
public function __toString()
{
$stringDeMalade = $this->getName().' '.$this->getAddress()->getLocality()->getPostalCode().' '.$this->getAddress()->getLocality()->getName();
return $stringDeMalade;
}
/**
* Add contact
*
* @param \VS\CrmBundle\Entity\Contact $contact
*
* @return Nursery
*/
public function addContact(\VS\CrmBundle\Entity\Contact $contact)
{
$this->contacts[] = $contact;
return $this;
}
/**
* Remove contact
*
* @param \VS\CrmBundle\Entity\Contact $contact
*/
public function removeContact(\VS\CrmBundle\Entity\Contact $contact)
{
$this->contacts->removeElement($contact);
}
/**
* Get contacts
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getContacts()
{
return $this->contacts;
}
/**
* Add registerRecord
*
* @param \VS\CrmBundle\Entity\RegisterRecord $registerRecord
*
* @return Nursery
*/
public function addRegisterRecord(\VS\CrmBundle\Entity\RegisterRecord $registerRecord)
{
$this->registerRecords[] = $registerRecord;
return $this;
}
/**
* Remove registerRecord
*
* @param \VS\CrmBundle\Entity\RegisterRecord $registerRecord
*/
public function removeRegisterRecord(\VS\CrmBundle\Entity\RegisterRecord $registerRecord)
{
$this->registerRecords->removeElement($registerRecord);
}
/**
* Get registerRecords
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRegisterRecords()
{
return $this->registerRecords;
}
}
Staff.php
<?php
namespace VS\CrmBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Staff
*
* @ORM\Table(name="staff")
* @ORM\Entity(repositoryClass="VS\CrmBundle\Repository\StaffRepository")
*/
class Staff extends User
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="staff_role", type="string", length=100)
*/
private $staffRole;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="Nursery", inversedBy="staff", cascade={"persist"})
* @ORM\JoinTable(name="nursery_staff")
*/
private $nurseries;
/**
* Staff constructor.
*/
public function __construct()
{
parent::__construct();
$this->nurseries = new ArrayCollection();
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set staffRole
*
* @param string $staffRole
*
* @return Staff
*/
public function setStaffRole($staffRole)
{
$this->staffRole = $staffRole;
return $this;
}
/**
* Get staffRole
*
* @return string
*/
public function getStaffRole()
{
return $this->staffRole;
}
/**
* @param Nursery $nursery
*/
public function addNurseries(Nursery $nursery)
{
$this->nurseries[] = $nursery;
}
/**
* @param Nursery $nursery
*/
public function removeNurseries(Nursery $nursery)
{
$this->nurseries->removeElement($nursery);
}
/**
* @return ArrayCollection
*/
public function getNurseries()
{
return $this->nurseries;
}
}
然后我想显示一个下拉菜单,其中包含所有与托儿所经理(具有 role = ROLE_MANAGER 的员工)相关联的托儿所,所以我有这个 Controller :
<?php
namespace VS\CrmBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use VS\CrmBundle\Entity\Staff;
use VS\CrmBundle\Form\StaffType;
class ManagerController extends Controller
{
public function dashboardAction($nursery_id)
{
$currentUser = $this->get('security.token_storage')->getToken()->getUser();
$nurseryRepo = $this->getDoctrine()->getRepository('VSCrmBundle:Nursery');
$nursery = $nurseryRepo->findOneBy(array(
'id' => $nursery_id,
'staff' => $currentUser
));
if(!$nursery)
{
throw $this->createNotFoundException("The nursery has not been found or you are not allowed to access it.");
}
return $this->render("VSCrmBundle:Manager:dashboard.html.twig", array(
'nursery' => $nursery
));
}
}
我可以在 View 中显示我的下拉列表:
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dashboards<span class="caret"></span></a>
<ul class="dropdown-menu">
{% if is_granted('ROLE_MANAGER') %}
<li class="dropdown-header">Nurseries</li>
{% for nursery in app.user.nurseries %}
<li><a href="{{ path('vs_crm_manager_dashboard', {'nursery_id' : nursery.id}) }}">{{ nursery.name }} dashboard</a></li>
{% endfor %}
{% endif %}
</ul>
</li>
但是当我点击一个随机的托儿所时,我有这个错误:
Catchable Fatal Error: Argument 1 passed to Doctrine\ORM\Mapping\DefaultQuoteStrategy::getJoinTableName() must be of the type array, null given, called in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php on line 1669 and defined 500 Internal Server Error - ContextErrorException**
日志:
[1] Symfony\Component\Debug\Exception\ContextErrorException: Catchable Fatal Error: Argument 1 passed to Doctrine\ORM\Mapping\DefaultQuoteStrategy::getJoinTableName() must be of the type array, null given, called in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php on line 1669 and defined
at n/a
in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\DefaultQuoteStrategy.php line 97
at Symfony\Component\Debug\ErrorHandler->handleError('4096', 'Argument 1 passed to Doctrine\ORM\Mapping\DefaultQuoteStrategy::getJoinTableName() must be of the type array, null given, called in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php on line 1669 and defined', 'C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\DefaultQuoteStrategy.php', '97', array())
in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\DefaultQuoteStrategy.php line 97
at Doctrine\ORM\Mapping\DefaultQuoteStrategy->getJoinTableName(null, object(ClassMetadata), object(MySQL57Platform))
in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php line 1669
at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectConditionStatementColumnSQL('staff', null)
in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php line 1582
at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectConditionStatementSQL('staff', object(Staff), null)
in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php line 1724
at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectConditionSQL(array('id' => '4', 'staff' => object(Staff)), null)
in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php line 1058
at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectSQL(array('id' => '4', 'staff' => object(Staff)), null, null, '1', null, null)
in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php line 710
at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->load(array('id' => '4', 'staff' => object(Staff)), null, null, array(), null, '1', null)
in C:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\EntityRepository.php line 196
at Doctrine\ORM\EntityRepository->findOneBy(array('id' => '4', 'staff' => object(Staff)))
in C:\wamp64\www\app\src\VS\CrmBundle\Controller\ManagerController.php line 21
at VS\CrmBundle\Controller\ManagerController->dashboardAction('4')
in line
at call_user_func_array(array(object(ManagerController), 'dashboardAction'), array('4'))
in C:\wamp64\www\app\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php line 153
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in C:\wamp64\www\app\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php line 68
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in C:\wamp64\www\app\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php line 169
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in C:\wamp64\www\app\web\app_dev.php line 28
那我做错了什么?也许做的方式不对?
最佳答案
请添加具有相对列名称的joinColumns 和inverseJoinColumns。
Staff.php
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="Nursery", inversedBy="staff", cascade={"persist"})
* @ORM\JoinTable(name="nursery_staff",
* joinColumns={@ORM\JoinColumn(name="nursery_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="staff_id", referencedColumnName="id")}
* )
*/
private $nurseries;
关于php - Symfony/Doctrine : getJoinTableName() must be of the type array, 给定为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41259422/
我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val
基本上,我只是试图在满足特定条件时停止程序运行其余行。unlessraw_information.firstputs"Noresultswerereturnedforthatquery"breakend然而,在程序运行之前我得到了这个错误:Invalidbreakcompileerror(SyntaxError)执行此操作的正确方法是什么? 最佳答案 abort("Noresultswerereturnedforthatquery")unlesscondition或unlessconditionabort("Noresultswer
目标我正在尝试计算自给定日期以来周的距离,而无需跳过任何步骤。我更喜欢用普通的Ruby来做,但ActiveSupport无疑是一个可以接受的选择。我的代码我写了以下内容,这似乎可行,但对我来说似乎还有很长的路要走。require'date'DAYS_IN_WEEK=7.0defweeks_sincedate_stringdate=Date.parsedate_stringdays=Date.today-dateweeks=days/DAYS_IN_WEEKweeks.round2endweeks_since'2015-06-15'#=>32.57ActiveSupport的#weeks
我有两个数组。第一个数组包含排序顺序。第二个数组包含任意数量的元素。我的属性是保证第二个数组中的所有元素(按值)都在第一个数组中,而且我只处理数字。A=[1,3,4,4,4,5,2,1,1,1,3,3]Order=[3,1,2,4,5]当我对A进行排序时,我希望元素按照Order指定的顺序出现:[3,3,3,1,1,1,1,2,4,4,4,5]请注意,重复是公平的游戏。A中的元素不应更改,只能重新排序。我该怎么做? 最佳答案 >>source=[1,3,4,4,4,5,2,1,1,1,3,3]=>[1,3,4,4,4,5,2,1,1
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我来自C、php和bash背景,很容易学习,因为它们都有相同的C结构,我可以将其与我已经知道的联系起来。然后2年前我学了Python并且学得很好,Python对我来说比Ruby更容易学。然后从去年开始,我一直在尝试学习Ruby,然后是Rails,我承认,直到现在我还是学不会,讽刺的是那些打着简单易学的烙印,但是对于我这样一个老练的程序员来说,我只是无法将它
我想生成一个包含数字、字母和特殊字符的给定(长度可能不同)长度的完全随机的“唯一”(我将确保使用我的模型)标识符例如:161551960578281|2.AQAIPhEcKsDLOVJZ.3600.1310065200.0-514191032|有人可以建议在RubyonRails中最有效的方法吗?编辑:重要:如果可能,请评论您提出的解决方案的效率,因为每次用户进入网站时都会使用它!谢谢 最佳答案 将其用于访问token与UUID不同。您不仅需要伪随机性,而且还需要加密安全PRNG.如果您真的不关心您使用的是什么字符(它们不会增加任何
我正在尝试从googleAPI下载client_secret.json。我正在执行https://developers.google.com/gmail/api/quickstart/ruby中列出的步骤.使用此向导在GoogleDevelopersConsole中创建或选择项目并自动启用API。在左侧边栏中,选择同意屏幕。选择电子邮件地址并输入产品名称(如果尚未设置),然后单击“保存”按钮。在左侧边栏中,选择凭据并点击创建新客户端ID。选择应用程序类型已安装应用程序,已安装应用程序类型为其他,然后单击“创建客户端ID”按钮。点击新客户端ID下的下载JSON按钮。将此文件移动到您的工作
我正在使用pggem从Ruby与PostgreSQL对话。有没有检查是否没有结果比使用res.ntuples==0更好的方法?conn=PGconn.connectconfigcmd="select*fromlabelsinnerjoinlabels_mailusing(label_id)"+"wherelabels_mail.mail_id=$1andlabels.name=$2"res=conn.exec(cmd,[mail_id,mailbox])ifres.ntuples==0# 最佳答案 元组,打字错误?使用zero?比=
我似乎找不到一种优雅的方式来做到这一点......给定一个日期,我如何找到下一个星期二,即日历月的第2个或第4个星期二?例如:给定2012-10-19然后返回2012-10-23或给定2012-10-31然后返回2012-11-13OctoberNovemberSuMoTuWeThFrSaSuMoTuWeThFrSa12345612378910111213456789101415161718192011121314151617212223242526271819202122232428293031252627282930 最佳答案
问题localhost:3000/users/不会显示我谦虚地进入,因为我是第一次尝试通过Rails教程。我在第10章,我已经花了5个小时解决这个问题。当我尝试访问localhost:3000/users/时出现错误(我相信这与factory_girl有关)解释了@users变量为空并且我忘记了为will_paginate传递一个集合对象。我目前在第10章第10.23节,每次运行时:$bundleexecrakedb:reset$bundleexecrakedb:populate$bundleexecrakedb:test:prepare我在解释时遇到错误rakeaborted!Fac