我有一个称为doerTrip的实体
namespace ApplicationEntity;
use DoctrineORMMapping as ORM;
/**
* Doer Trip
*
* @ORMTable(name="doer_trip")
* @ORMEntity
*/
class DoerTrip extends AbstractEntity
{
const STATUS_PUBLISHED = 1;
const STATUS_UNPUBLISHED = 0;
/**
* @var integer
*
* @ORMColumn(name="`id`", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var ApplicationEntityDoer
*
* @ORMManyToOne(targetEntity="Doer")
* @ORMJoinColumn(name="`doer_id`", referencedColumnName="id")
*/
protected $doer; // inversedBy="trips"
/**
* @var ApplicationEntityTrip
*
* @ORMManyToOne(targetEntity="Trip")
* @ORMJoinColumn(name="`trip_id`", referencedColumnName="id")
*/
protected $trip; //inversedBy="doers"
/**
* @var bool
*
* @ORMColumn(name="`published`", type="boolean")
*/
protected $published;
/**
* @var string
*
* @ORMColumn(name="`comment`", type="text")
*/
protected $comment;
/**
* @var integer
*
* @ORMColumn(name="`target_sum`", type="integer")
*/
protected $targetSum;
public function __construct()
{
$this->published = false;
}
/**
* @param string $comment
* @return $this
*/
public function setComment($comment)
{
$this->comment = $comment;
return $this;
}
/**
* @return string
*/
public function getComment()
{
return $this->comment;
}
/**
* @param ApplicationEntityDoer $doer
* @return $this
*/
public function setDoer(Doer $doer)
{
$this->doer = $doer;
return $this;
}
/**
* @return ApplicationEntityDoer
*/
public function getDoer()
{
return $this->doer;
}
/**
* @param int $id
* @return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param boolean $published
* @return $this
*/
public function setPublished($published)
{
$this->published = $published;
return $this;
}
/**
* @return boolean
*/
public function getPublished()
{
return $this->published;
}
/**
* @param ApplicationEntityTrip $trip
* @return $this
*/
public function setTrip(Trip $trip)
{
$this->trip = $trip;
return $this;
}
/**
* @return ApplicationEntityTrip
*/
public function getTrip()
{
return $this->trip;
}
/**
* @param int $targetSum
* @return $this
*/
public function setTargetSum($targetSum)
{
$this->targetSum = $targetSum;
return $this;
}
/**
* @return int
*/
public function getTargetSum()
{
return (null !== $this->targetSum) ? $this->targetSum : $this->getTrip()->getTargetAmount();
}
}
这里旅行实体:
namespace ApplicationEntity;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineCommonCollectionsCollection;
use DoctrineORMMapping as ORM;
use ZendValidatorIsInstanceOf;
/**
* Trip
*
* @ORMTable(name="trip")
* @ORMEntity
*/
class Trip extends AbstractEntity
{
const STATUS_ACTIVE = 'active';
const STATUS_INACTIVE = 'inactive';
const STATUS_BANNED = 'banned';
/**
* @var string
*
* @ORMColumn(name="name", type="string", length=255)
*/
protected $name;
/**
* @var Collection
*
* @ORMManyToMany(targetEntity="Media", cascade={"remove"}, orphanRemoval=true)
* @ORMJoinTable(name="trip_media",
* joinColumns={@ORMJoinColumn(name="trip_id", referencedColumnName="id")},
* inverseJoinColumns={@ORMJoinColumn(name="file_id", referencedColumnName="id", unique=true)}
* )
*/
protected $media;
/**
* @var ApplicationEntityMedia
*
* @ORMOneToOne(targetEntity="Media", mappedBy="trip", cascade={"persist", "remove"})
* @ORMJoinColumn(name="main_media_id", referencedColumnName="id")
*/
protected $mainMedia;
/**
* @var string
*
* @ORMColumn(name="api_key", type="string", length=255)
*/
protected $apiKey;
/**
* @var string
*
* @ORMColumn(name="country", type="string", length=255, nullable=true)
*/
protected $country;
/**
* @var DateTime
*
* @ORMColumn(name="departure_date", type="date", nullable=true)
*/
protected $departureDate;
/**
* @var DateTime
*
* @ORMColumn(name="due_date", type="date", nullable=true)
*/
protected $dueDate;
/**
* @var DateTime
*
* @ORMColumn(name="return_date", type="date", nullable=true)
*/
protected $returnDate;
/**
* @var string
*
* @ORMColumn(name="description", type="text", nullable=true)
*/
protected $description;
/**
* @var string
*
* @ORMColumn(name="target_amount", type="integer")
*/
protected $targetAmount;
/**
* @var Collection
*
* @ORMOneToMany(targetEntity="DoerTrip", mappedBy="trip", cascade={"persist","remove"}, orphanRemoval=true)
*/
protected $doers;
/**
* @var Organization
*
* @ORMManyToOne(targetEntity="Organization", inversedBy="trips")
* @ORMJoinColumn(name="organization_id", referencedColumnName="id")
*/
protected $organization;
/**
* @var Cause
*
* @ORMOneToOne(targetEntity="Cause", inversedBy="trips")
* @ORMJoinColumn(name="cause_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $cause;
/**
* @var integer
*
* @ORMColumn(name="status", type="string" ,columnDefinition="ENUM('active', 'inactive', 'banned')")
*/
protected $status;
/**
* @var integer
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var Transaction
*
* @ORMOneToMany(targetEntity="Transaction", mappedBy="trip", cascade={"remove"}, orphanRemoval=true)
*/
protected $transactions;
/**
* @param Organization $organization
* @return $this
*/
public function setOrganization(Organization $organization)
{
$this->organization = $organization;
return $this;
}
/**
* @return Organization
*/
public function getOrganization()
{
return $this->organization;
}
public function __construct()
{
$this->doers = new ArrayCollection();
$this->media = new ArrayCollection();
$this->status = self::STATUS_ACTIVE;
$this->transactions = new ArrayCollection();
$this->targetAmount = 0;
$this->description = '';
}
/**
* @param string $apiKey
* @return $this
*/
public function setApiKey($apiKey)
{
$this->apiKey = $apiKey;
return $this;
}
/**
* @return string
*/
public function getApiKey()
{
return $this->apiKey;
}
/**
* @param string $country
* @return $this
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* @param string $description
* @return $this
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param DateTime $dueDate
* @return $this
*/
public function setDueDate(DateTime $dueDate)
{
$this->dueDate = $dueDate;
return $this;
}
/**
* @return DateTime
*/
public function getDueDate()
{
return $this->dueDate;
}
/**
* @param int $id
* @return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param DateTime $departureDate
* @return $this
*/
public function setDepartureDate(DateTime $departureDate)
{
$this->departureDate = $departureDate;
return $this;
}
/**
* @return DateTime
*/
public function getDepartureDate()
{
return $this->departureDate;
}
/**
* @param string $targetAmount
* @return $this
*/
public function setTargetAmount($targetAmount)
{
$this->targetAmount = $targetAmount;
return $this;
}
/**
* @return string
*/
public function getTargetAmount()
{
return $this->targetAmount;
}
/**
* @param string $name
* @return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param int $status
* @return $this
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* @return int
*/
public function getStatus()
{
return $this->status;
}
/**
* @param ApplicationEntityCause $cause
* @return $this
*/
public function setCause($cause)
{
$this->cause = $cause;
return $this;
}
/**
* @return ApplicationEntityCause
*/
public function getCause()
{
return $this->cause;
}
/**
* @param DoctrineCommonCollectionsCollection $media
* @return $this
*/
public function setMedia($media)
{
$this->media = $media;
return $this;
}
/**
* @return DoctrineCommonCollectionsCollection
*/
public function getMedia()
{
return $this->media;
}
/**
* @param ApplicationEntityDoerTrip $doer
* @return $this
*/
public function addDoer(DoerTrip $doer)
{
$this->doers->add($doer);
$doer->setTrip($this);
return $this;
}
/**
* @param Collection $doers
* @return $this
*/
public function setDoers(Collection $doers)
{
$this->doers = $doers;
return $this;
}
/**
* @return Collection
*/
public function getDoers()
{
return $this->doers;
}
/**
* @param ApplicationEntityDoerTrip $doer
* @return $this
*/
public function removeDoer(DoerTrip $doer)
{
$this->doers->removeElement($doer);
return $this;
}
/**
* @param DoctrineCommonCollectionsCollection $transactions
* @return $this
*/
public function setTransactions($transactions)
{
$this->transactions = $transactions;
return $this;
}
/**
* @return DoctrineCommonCollectionsCollection
*/
public function getTransactions()
{
return $this->transactions;
}
/**
* @param array $data
* @return $this
*/
public function populate(array $data)
{
if (!empty($data['departureDate']) && !$data['departureDate'] instanceof DateTime) {
$data['departureDate'] = new DateTime($data['departureDate']);
}
if (!empty($data['dueDate']) && !$data['dueDate'] instanceof DateTime) {
$data['dueDate'] = new DateTime($data['dueDate']);
}
if (!empty($data['returnDate']) && !$data['returnDate'] instanceof DateTime) {
$data['returnDate'] = new DateTime($data['returnDate']);
}
parent::populate($data);
return $this;
}
/**
* @param DateTime $returnDate
* @return $this
*/
public function setReturnDate(DateTime $returnDate)
{
$this->returnDate = $returnDate;
return $this;
}
/**
* @return DateTime
*/
public function getReturnDate()
{
return $this->returnDate;
}
/**
* @param ApplicationEntityMedia $mainMedia
* @return $this
*/
public function setMainMedia($mainMedia)
{
$this->mainMedia = $mainMedia;
return $this;
}
/**
* @return ApplicationEntityMedia
*/
public function getMainMedia()
{
return $this->mainMedia;
}
/**
* @param Media $media
* @return bool
*/
public function hasMedia(Media $media)
{
return $this->getMedia()->contains($media);
}
/**
* @param ApplicationEntityMedia $media
* @return $this
*/
public function addMedia(Media $media)
{
$this->media->add($media);
return $this;
}
/**
* @param ApplicationEntityMedia $media
* @return $this
*/
public function removeMedia(Media $media)
{
$this->media->removeElement($media);
return $this;
}
}
这是doer实体
namespace ApplicationEntity;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineCommonCollectionsCollection;
use DoctrineORMMapping as ORM;
use ZendValidatorIsInstanceOf;
/**
* Trip
*
* @ORMTable(name="trip")
* @ORMEntity
*/
class Trip extends AbstractEntity
{
const STATUS_ACTIVE = 'active';
const STATUS_INACTIVE = 'inactive';
const STATUS_BANNED = 'banned';
/**
* @var string
*
* @ORMColumn(name="name", type="string", length=255)
*/
protected $name;
/**
* @var Collection
*
* @ORMManyToMany(targetEntity="Media", cascade={"remove"}, orphanRemoval=true)
* @ORMJoinTable(name="trip_media",
* joinColumns={@ORMJoinColumn(name="trip_id", referencedColumnName="id")},
* inverseJoinColumns={@ORMJoinColumn(name="file_id", referencedColumnName="id", unique=true)}
* )
*/
protected $media;
/**
* @var ApplicationEntityMedia
*
* @ORMOneToOne(targetEntity="Media", mappedBy="trip", cascade={"persist", "remove"})
* @ORMJoinColumn(name="main_media_id", referencedColumnName="id")
*/
protected $mainMedia;
/**
* @var string
*
* @ORMColumn(name="api_key", type="string", length=255)
*/
protected $apiKey;
/**
* @var string
*
* @ORMColumn(name="country", type="string", length=255, nullable=true)
*/
protected $country;
/**
* @var DateTime
*
* @ORMColumn(name="departure_date", type="date", nullable=true)
*/
protected $departureDate;
/**
* @var DateTime
*
* @ORMColumn(name="due_date", type="date", nullable=true)
*/
protected $dueDate;
/**
* @var DateTime
*
* @ORMColumn(name="return_date", type="date", nullable=true)
*/
protected $returnDate;
/**
* @var string
*
* @ORMColumn(name="description", type="text", nullable=true)
*/
protected $description;
/**
* @var string
*
* @ORMColumn(name="target_amount", type="integer")
*/
protected $targetAmount;
/**
* @var Collection
*
* @ORMOneToMany(targetEntity="DoerTrip", mappedBy="trip", cascade={"persist","remove"}, orphanRemoval=true)
*/
protected $doers;
/**
* @var Organization
*
* @ORMManyToOne(targetEntity="Organization", inversedBy="trips")
* @ORMJoinColumn(name="organization_id", referencedColumnName="id")
*/
protected $organization;
/**
* @var Cause
*
* @ORMOneToOne(targetEntity="Cause", inversedBy="trips")
* @ORMJoinColumn(name="cause_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $cause;
/**
* @var integer
*
* @ORMColumn(name="status", type="string" ,columnDefinition="ENUM('active', 'inactive', 'banned')")
*/
protected $status;
/**
* @var integer
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var Transaction
*
* @ORMOneToMany(targetEntity="Transaction", mappedBy="trip", cascade={"remove"}, orphanRemoval=true)
*/
protected $transactions;
/**
* @param Organization $organization
* @return $this
*/
public function setOrganization(Organization $organization)
{
$this->organization = $organization;
return $this;
}
/**
* @return Organization
*/
public function getOrganization()
{
return $this->organization;
}
public function __construct()
{
$this->doers = new ArrayCollection();
$this->media = new ArrayCollection();
$this->status = self::STATUS_ACTIVE;
$this->transactions = new ArrayCollection();
$this->targetAmount = 0;
$this->description = '';
}
/**
* @param string $apiKey
* @return $this
*/
public function setApiKey($apiKey)
{
$this->apiKey = $apiKey;
return $this;
}
/**
* @return string
*/
public function getApiKey()
{
return $this->apiKey;
}
/**
* @param string $country
* @return $this
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* @param string $description
* @return $this
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param DateTime $dueDate
* @return $this
*/
public function setDueDate(DateTime $dueDate)
{
$this->dueDate = $dueDate;
return $this;
}
/**
* @return DateTime
*/
public function getDueDate()
{
return $this->dueDate;
}
/**
* @param int $id
* @return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param DateTime $departureDate
* @return $this
*/
public function setDepartureDate(DateTime $departureDate)
{
$this->departureDate = $departureDate;
return $this;
}
/**
* @return DateTime
*/
public function getDepartureDate()
{
return $this->departureDate;
}
/**
* @param string $targetAmount
* @return $this
*/
public function setTargetAmount($targetAmount)
{
$this->targetAmount = $targetAmount;
return $this;
}
/**
* @return string
*/
public function getTargetAmount()
{
return $this->targetAmount;
}
/**
* @param string $name
* @return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param int $status
* @return $this
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* @return int
*/
public function getStatus()
{
return $this->status;
}
/**
* @param ApplicationEntityCause $cause
* @return $this
*/
public function setCause($cause)
{
$this->cause = $cause;
return $this;
}
/**
* @return ApplicationEntityCause
*/
public function getCause()
{
return $this->cause;
}
/**
* @param DoctrineCommonCollectionsCollection $media
* @return $this
*/
public function setMedia($media)
{
$this->media = $media;
return $this;
}
/**
* @return DoctrineCommonCollectionsCollection
*/
public function getMedia()
{
return $this->media;
}
/**
* @param ApplicationEntityDoerTrip $doer
* @return $this
*/
public function addDoer(DoerTrip $doer)
{
$this->doers->add($doer);
$doer->setTrip($this);
return $this;
}
/**
* @param Collection $doers
* @return $this
*/
public function setDoers(Collection $doers)
{
$this->doers = $doers;
return $this;
}
/**
* @return Collection
*/
public function getDoers()
{
return $this->doers;
}
/**
* @param ApplicationEntityDoerTrip $doer
* @return $this
*/
public function removeDoer(DoerTrip $doer)
{
$this->doers->removeElement($doer);
return $this;
}
/**
* @param DoctrineCommonCollectionsCollection $transactions
* @return $this
*/
public function setTransactions($transactions)
{
$this->transactions = $transactions;
return $this;
}
/**
* @return DoctrineCommonCollectionsCollection
*/
public function getTransactions()
{
return $this->transactions;
}
/**
* @param array $data
* @return $this
*/
public function populate(array $data)
{
if (!empty($data['departureDate']) && !$data['departureDate'] instanceof DateTime) {
$data['departureDate'] = new DateTime($data['departureDate']);
}
if (!empty($data['dueDate']) && !$data['dueDate'] instanceof DateTime) {
$data['dueDate'] = new DateTime($data['dueDate']);
}
if (!empty($data['returnDate']) && !$data['returnDate'] instanceof DateTime) {
$data['returnDate'] = new DateTime($data['returnDate']);
}
parent::populate($data);
return $this;
}
/**
* @param DateTime $returnDate
* @return $this
*/
public function setReturnDate(DateTime $returnDate)
{
$this->returnDate = $returnDate;
return $this;
}
/**
* @return DateTime
*/
public function getReturnDate()
{
return $this->returnDate;
}
/**
* @param ApplicationEntityMedia $mainMedia
* @return $this
*/
public function setMainMedia($mainMedia)
{
$this->mainMedia = $mainMedia;
return $this;
}
/**
* @return ApplicationEntityMedia
*/
public function getMainMedia()
{
return $this->mainMedia;
}
/**
* @param Media $media
* @return bool
*/
public function hasMedia(Media $media)
{
return $this->getMedia()->contains($media);
}
/**
* @param ApplicationEntityMedia $media
* @return $this
*/
public function addMedia(Media $media)
{
$this->media->add($media);
return $this;
}
/**
* @param ApplicationEntityMedia $media
* @return $this
*/
public function removeMedia(Media $media)
{
$this->media->removeElement($media);
return $this;
}
}
我执行此代码样本:
$doerTrip = new DoerTrip();
$doerTrip->setDoer($doer)->setTrip($trip);
$em->persist($doerTrip);
$em->flush();
本地工作(在Windows上)。但是,在登台(Ubuntu)时,没有创建新记录,我没有任何错误。更新实体DOERTRIP上的分期也无法正常工作。
如果我在连接的帮助下执行插入
$stmt = $conn->prepare('INSERT INTO doer_trip (...) VALUES (?,?,?,?,?)');
$stmt->bindParam(1, $param);
...
一切正常。在SQL Logger中使用ORM时,我可以看到
START TRANSACTION;
INSERT INTO doer_trip (...) VALUES (?,?,?,?,?)
COMMIT;
,但在登台时并未创建新记录。本地一切正常。
我不知道这可能取决于mySQL配置。
我不知道。
在这里我的doer_trip表
CREATE TABLE `doer_trip` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`doer_id` INT(11) NOT NULL,
`trip_id` INT(11) UNSIGNED NOT NULL,
`published` INT(1) UNSIGNED NOT NULL DEFAULT '0',
`comment` TEXT NULL,
`target_sum` INT(10) UNSIGNED NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `doer_id` (`doer_id`),
INDEX `trip_id` (`trip_id`),
UNIQUE INDEX `doer_iduniq` (`doer_id`, `trip_id`),
CONSTRAINT `FK_doer_trip_trip` FOREIGN KEY (`trip_id`) REFERENCES `trip` (`id`),
CONSTRAINT `FK_doer_trip_doer` FOREIGN KEY (`doer_id`) REFERENCES `doer` (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=41
问题在
中/**
* @var bool
*
* @ORMColumn(name="`published`", type="boolean")
*/
protected $published;
如果我将类型设置为像这样的整数
/**
* @var integer
*
* @ORMColumn(name="`published`", type="integer")
*/
protected $published;
一切正常。但是为什么它在我当地的环境中正常工作???