在SQL中它应该如下所示:
SELECT * FROM `categories_description_old` WHERE ((`categories_description` = '') OR (`categories_name` = '') OR (`categories_heading_title` = ''))
Run Code Online (Sandbox Code Playgroud)
我(丑陋)的解决方案:
conditions = [:categories_name, :categories_heading_title, :categories_description]
b = table_categories_description_old.filter(conditions.pop => "")
conditions.each do |m|
b = b.or(m => "")
end
Run Code Online (Sandbox Code Playgroud)
是否有更好的解决方案来链接或条件?
当我运行Thor任务时,是否可以先调用特定任务?
我的Thorfile:
class Db < Thor
desc "show_Version", "some description ..."
def show_version # <= needs a database connection
puts ActiveRecord::Migrator.current_version
end
private
def connect_to_database # <= call this always when a task from this file is executed
# connect here to database
end
end
Run Code Online (Sandbox Code Playgroud)
我可以在每个任务中编写"connect_to_database"方法,但这看起来不是很干.
我在正确设置教义映射时遇到问题。
我有一个CashRegister实体,该实体具有容器位置和返回容器位置。两个位置都来自相同的类型(BinLocation实体)。
从发出CashRegister,CashRegister->getBinLocations()并且CashRegister->getReturnBinLocations()工作正常,但是如何实现BinLocation->getCashRegisters()返回所有CashRegister引用的实体(binLocation+ returnBinLocation)?
/**
* CashRegister
*
* @ORM\Table(name="cash_registers")
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
*/
class CashRegister
{
...
/**
* @var BinLocation
*
* @ORM\ManyToOne(targetEntity="BinLocation", inversedBy="cashRegisters")
* @ORM\JoinColumn(name="bin_location_id", referencedColumnName="id")
*/
private $binLocation;
/**
* @var BinLocation
*
* @ORM\ManyToOne(targetEntity="BinLocation", inversedBy="cashRegisters")
* @ORM\JoinColumn(name="return_bin_location_id", referencedColumnName="id")
*/
private $returnBinLocation;
/**
* @return BinLocation
*/
public function getBinLocation()
{
return $this->binLocation;
}
/**
* @return BinLocation …Run Code Online (Sandbox Code Playgroud)