下面的查询没有给出任何结果。
$query = $this->em->createQuery("
SELECT cs, cc
FROM AppEntityContinents cs
JOIN cs.countries cc
WHERE cs.enabled = 1 AND cs.deleted = 0
");
如果我使用" print_r($ query)"打印查询;它打印对象...但是,如果我尝试使用" print($ query-> getsql())获得SQL;它行不通。
任何帮助都将不胜感激。
请注意:它可以很好地工作。
实体映射
国家实体
/** * @entity(repositorityClass =" App Repository Contrents") * @Table(name =" nistry") */班级国家{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORMManyToOne(targetEntity="AppEntityContinents", inversedBy="countries")
* @ORMJoinColumn(name="id", referencedColumnName="continent_id")
*/
protected $continents;
/** @Column(type="integer", length=1) */
protected $continent_id;
/** @Column(type="string", length=3) */
protected $iso_number;
/** @Column(type="string", length=2) */
protected $iso_2_code;
/** @Column(type="string", length=3) */
protected $iso_3_code;
/** @Column(type="string", length=45) */
protected $name;
/** @Column(type="string", length=3) */
protected $default_currency;
/** @Column(type="string", length=3) */
protected $currency_symbol;
/** @Column(type="integer", length=3) */
protected $currency_id;
/** @Column(type="integer", length=1) */
protected $postcode_check;
/** @Column(type="string", length=150) */
protected $postcode_regex;
/** @Column(type="integer", length=1) */
protected $enabled;
/** @Column(type="integer", length=1) */
protected $deleted;
/** @Column(type="datetime") */
protected $created;
/** @Column(type="integer", length=11) */
protected $created_by;
/** @Column(type="datetime") */
protected $modified;
/** @Column(type="integer", length=11) */
protected $modified_by;
public function __construct() {
}
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
}
public function getContinents() {
return $this->continents;
}
public function setContinents(AppEntityContinents $continents) {
$this->continents = $continents;
}
public function getContinent_id() {
return $this->continent_id;
}
public function setContinent_id($continent_id) {
$this->continent_id = $continent_id;
}
public function getIso_number() {
return $this->iso_number;
}
public function setIso_number($iso_number) {
$this->iso_number = $iso_number;
}
public function getIso_2_code() {
return $this->iso_2_code;
}
public function setIso_2_code($iso_2_code) {
$this->iso_2_code = $iso_2_code;
}
public function getIso_3_code() {
return $this->iso_3_code;
}
public function setIso_3_code($iso_3_code) {
$this->iso_3_code = $iso_3_code;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function getDefault_currency() {
return $this->default_currency;
}
public function setDefault_currency($default_currency) {
$this->default_currency = $default_currency;
}
public function getCurrency_symbol() {
return $this->currency_symbol;
}
public function setCurrency_symbol($currency_symbol) {
$this->currency_symbol = $currency_symbol;
}
public function getCurrency_id() {
return $this->currency_id;
}
public function setCurrency_id($currency_id) {
$this->currency_id = $currency_id;
}
public function getPostcode_check() {
return $this->postcode_check;
}
public function setPostcode_check($postcode_check) {
$this->postcode_check = $postcode_check;
}
public function getPostcode_regex() {
return $this->postcode_regex;
}
public function setPostcode_regex($postcode_regex) {
$this->postcode_regex = $postcode_regex;
}
public function getEnabled() {
return $this->enabled;
}
public function setEnabled($enabled) {
$this->enabled = $enabled;
}
public function getDeleted() {
return $this->deleted;
}
public function setDeleted($deleted) {
$this->deleted = $deleted;
}
public function getCreated() {
return $this->created;
}
public function setCreated($created) {
$this->created = $created;
}
public function getModified() {
return $this->modified;
}
public function setModified($modified) {
$this->modified = $modified;
}
public function getCreated_by() {
return $this->created_by;
}
public function setCreated_by($created_by) {
$this->created_by = $created_by;
}
public function getModified_by() {
return $this->modified_by;
}
public function setModified_by($modified_by) {
$this->modified_by = $modified_by;
}
}
大陆实体
/** * @实体 * @Table(名称="大陆") */班级大洲{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORMOneToMany(targetEntity="AppEntityCountries", mappedBy="continents")
*/
protected $countries;
/** @Column(type="string", length=7) */
protected $name;
/** @Column(type="integer", length=1) */
protected $enabled;
/** @Column(type="integer", length=1) */
protected $deleted;
/** @Column(type="datetime") */
protected $created;
/** @Column(type="integer", length=11) */
protected $created_by;
/** @Column(type="datetime") */
protected $modified;
/** @Column(type="integer", length=11) */
protected $modified_by;
public function __construct() {
$this->countries = new ArrayCollection();
}
public function getCountries() {
return $this->countries;
}
public function setCountries($countries) {
$this->countries = $countries;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
}
public function getCreated_by() {
return $this->created_by;
}
public function setCreated_by($created_by) {
$this->created_by = $created_by;
}
public function getModified_by() {
return $this->modified_by;
}
public function setModified_by($modified_by) {
$this->modified_by = $modified_by;
}
public function getEnabled() {
return $this->enabled;
}
public function setEnabled($enabled) {
$this->enabled = $enabled;
}
public function getDeleted() {
return $this->deleted;
}
public function setDeleted($deleted) {
$this->deleted = $deleted;
}
public function getCreated() {
return $this->created;
}
public function setCreated($created) {
$this->created = $created;
}
public function getModified() {
return $this->modified;
}
public function setModified($modified) {
$this->modified = $modified;
}
}
我不知道您拥有的这个列名称,但您应该通过这样的回头逃脱它:
SELECT cs.* , cc.* -- //--you are selecting tables.
FROM `Continents` cs --escape by backticks here
JOIN countries cc --no need cs here
ON ............ --condition here (relation between the two tables)
WHERE cs.enabled = 1 AND cs.deleted = 0 --this is good
此问题已解决。问题在于我的实体。我以下更新了我的大洲和国家实体,效果很好。我希望这会帮助别人。
/** * @entity(repositorityClass =" App Repository Contrents") * @Table(名称="大陆") */班级大洲{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORMOneToMany(targetEntity="AppEntityCountries", mappedBy="continents")
*/
protected $countries;
/** @Column(type="string", length=7) */
protected $name;
/** @Column(type="integer", length=1) */
protected $enabled;
/** @Column(type="integer", length=1) */
protected $deleted;
/** @Column(type="datetime") */
protected $created;
/** @Column(type="integer", length=11) */
protected $created_by;
/** @Column(type="datetime") */
protected $modified;
/** @Column(type="integer", length=11) */
protected $modified_by;
public function __construct() {
$this->countries = new ArrayCollection();
}
public function getCountries() {
return $this->countries;
}
public function setCountries($countries) {
$this->countries = $countries;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
}
public function getCreated_by() {
return $this->created_by;
}
public function setCreated_by($created_by) {
$this->created_by = $created_by;
}
public function getModified_by() {
return $this->modified_by;
}
public function setModified_by($modified_by) {
$this->modified_by = $modified_by;
}
public function getEnabled() {
return $this->enabled;
}
public function setEnabled($enabled) {
$this->enabled = $enabled;
}
public function getDeleted() {
return $this->deleted;
}
public function setDeleted($deleted) {
$this->deleted = $deleted;
}
public function getCreated() {
return $this->created;
}
public function setCreated($created) {
$this->created = $created;
}
public function getModified() {
return $this->modified;
}
public function setModified($modified) {
$this->modified = $modified;
}
}
/** * @entity(repositorityClass =" App Repository Contrents") * @Table(name =" nistry") */班级国家{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORMManyToOne(targetEntity="AppEntityContinents", inversedBy="countries")
* @ORMJoinColumn(name="continent_id", referencedColumnName="id")
*/
protected $continents;
/** @Column(type="integer", length=1) */
protected $continent_id;
/** @Column(type="string", length=3) */
protected $iso_number;
/** @Column(type="string", length=2) */
protected $iso_2_code;
/** @Column(type="string", length=3) */
protected $iso_3_code;
/** @Column(type="string", length=45) */
protected $name;
/** @Column(type="string", length=3) */
protected $default_currency;
/** @Column(type="string", length=3) */
protected $currency_symbol;
/** @Column(type="integer", length=3) */
protected $currency_id;
/** @Column(type="integer", length=1) */
protected $postcode_check;
/** @Column(type="string", length=150) */
protected $postcode_regex;
/** @Column(type="integer", length=1) */
protected $enabled;
/** @Column(type="integer", length=1) */
protected $deleted;
/** @Column(type="datetime") */
protected $created;
/** @Column(type="integer", length=11) */
protected $created_by;
/** @Column(type="datetime") */
protected $modified;
/** @Column(type="integer", length=11) */
protected $modified_by;
public function __construct() {
}
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
}
public function getContinents() {
return $this->continents;
}
public function setContinents(AppEntityContinents $continents) {
$this->continents = $continents;
}
public function getContinent_id() {
return $this->continent_id;
}
public function setContinent_id($continent_id) {
$this->continent_id = $continent_id;
}
public function getIso_number() {
return $this->iso_number;
}
public function setIso_number($iso_number) {
$this->iso_number = $iso_number;
}
public function getIso_2_code() {
return $this->iso_2_code;
}
public function setIso_2_code($iso_2_code) {
$this->iso_2_code = $iso_2_code;
}
public function getIso_3_code() {
return $this->iso_3_code;
}
public function setIso_3_code($iso_3_code) {
$this->iso_3_code = $iso_3_code;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function getDefault_currency() {
return $this->default_currency;
}
public function setDefault_currency($default_currency) {
$this->default_currency = $default_currency;
}
public function getCurrency_symbol() {
return $this->currency_symbol;
}
public function setCurrency_symbol($currency_symbol) {
$this->currency_symbol = $currency_symbol;
}
public function getCurrency_id() {
return $this->currency_id;
}
public function setCurrency_id($currency_id) {
$this->currency_id = $currency_id;
}
public function getPostcode_check() {
return $this->postcode_check;
}
public function setPostcode_check($postcode_check) {
$this->postcode_check = $postcode_check;
}
public function getPostcode_regex() {
return $this->postcode_regex;
}
public function setPostcode_regex($postcode_regex) {
$this->postcode_regex = $postcode_regex;
}
public function getEnabled() {
return $this->enabled;
}
public function setEnabled($enabled) {
$this->enabled = $enabled;
}
public function getDeleted() {
return $this->deleted;
}
public function setDeleted($deleted) {
$this->deleted = $deleted;
}
public function getCreated() {
return $this->created;
}
public function setCreated($created) {
$this->created = $created;
}
public function getModified() {
return $this->modified;
}
public function setModified($modified) {
$this->modified = $modified;
}
public function getCreated_by() {
return $this->created_by;
}
public function setCreated_by($created_by) {
$this->created_by = $created_by;
}
public function getModified_by() {
return $this->modified_by;
}
public function setModified_by($modified_by) {
$this->modified_by = $modified_by;
}
}