小编ips*_*sum的帖子

怎么写得更好?Ruby Sequel链接OR

在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)

是否有更好的解决方案来链接或条件?

ruby chaining sequel

9
推荐指数
2
解决办法
2036
查看次数

Ruby - Thor首先执行特定任务

当我运行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"方法,但这看起来不是很干.

ruby initialization task thor

7
推荐指数
1
解决办法
4473
查看次数

教义2的多重映射

我在正确设置教义映射时遇到问题。

我有一个CashRegister实体,该实体具有容器位置和返回容器位置。两个位置都来自相同的类型(BinLocation实体)。

从发出CashRegisterCashRegister->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)

php mapping orm symfony doctrine-orm

5
推荐指数
1
解决办法
3508
查看次数

标签 统计

ruby ×2

chaining ×1

doctrine-orm ×1

initialization ×1

mapping ×1

orm ×1

php ×1

sequel ×1

symfony ×1

task ×1

thor ×1