学说2.0中的一对多关系问题
我有一个事件表和事件图像表。我有一个表单来添加新事件,因此我还为该事件添加多个图像。这样我就存储在事件图像表中。
那么我如何在两个表中插入数据..
<?php
/**
* @Entity
* @Table(name="events")
*/
class Default_Model_Event
{
/**
* @Id @Column(name="id", type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Column(name="title", type="string")
*/
private $title;
/**
* @OneToMany(targetEntity="Default_Model_EventImages" mappedBy="eventimage_mapper")
*/
private $images_mapper;
}//end class
事件图像模型
<?php
/**
* @Entity
* @Table(name="event_images")
*/
class Default_Model_EventImages
{
/**
* @Id @Column(name="id", type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Column(name="name", type="string")
*/
private $name;
/**
* @ManyToOne(targetEntity="Default_Model_Event", inversedBy="images_mapper")
* @JoinColumn(name="event_id", referencedColumnName="id")
*/
private $eventimage_mapper;
}//end class
从我的控制器现在如何保存数据..我正在考虑首先保存事件数据,然后将获取该ID,然后将保存事件图像通过循环..比我不明白我创建的一对多映射器的用途是什么..
我正在使用 zend Framework 1.11 和 Doctrine 2.0
I have an events table and events images table. I am having a form to add new event so i am also adding multiple images for that event. So that i am storing in event images table.
so how do i insert the data in both the tables..
<?php
/**
* @Entity
* @Table(name="events")
*/
class Default_Model_Event
{
/**
* @Id @Column(name="id", type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Column(name="title", type="string")
*/
private $title;
/**
* @OneToMany(targetEntity="Default_Model_EventImages" mappedBy="eventimage_mapper")
*/
private $images_mapper;
}//end class
Event images model
<?php
/**
* @Entity
* @Table(name="event_images")
*/
class Default_Model_EventImages
{
/**
* @Id @Column(name="id", type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Column(name="name", type="string")
*/
private $name;
/**
* @ManyToOne(targetEntity="Default_Model_Event", inversedBy="images_mapper")
* @JoinColumn(name="event_id", referencedColumnName="id")
*/
private $eventimage_mapper;
}//end class
From my controller how do i save the data now.. I am thinking of first saving the event data and than will get that id and than will save the events images by loop.. than i am not getting what will be the use of the one to many mapper i have created..
I am using zend framework 1.11 and Doctrine 2.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要为对象创建 getter 和 setter。然后你只需创建
只需阅读有关关联的 Doctrine 文档即可。这肯定会有帮助。
At first you need to create getters, setters to your objects. Then you just create
Just read the Doctrine documentation on associations. It will help for sure.