Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
static::query() doesn't support column/field alias?
  • I have this model:
    class Model_Philhealth extends Orm\Model
      protected static $_table_name = 'philhealth_contribution';
    // protected static $_properties = array(
    // 'id',
    // 'SalaryRange_From', 'SalaryRange_To'
    // );

        protected static $_observers = array(
            // This typing should be modified to format and return only the specified fields!

         * @param $monthlyBasicPay
         * @param int $year                 date('Y')
         * @return bool|array
    public static function getShare($monthlyBasicPay, $year = 2014)
            // query() doesn't support column alias
            $share = static::query()
                ->select('EmployeeShare', 'EmployerShare', 'SalaryBase')
                ->where('year', $year)
                ->where('SalaryRange_From', '<=', $monthlyBasicPay) // $monthlyBasicPay >= SalaryRange_From
                ->where('SalaryRange_To', '>=', $monthlyBasicPay)   // $monthlyBasicPay <= SalaryRange_To
            // % - get from phic
            $premiumRate = 2.5;

            $share['Employee'] = ($share['SalaryBase'] * ($premiumRate / 100) / 2);
            $share['Employer'] = ($share['SalaryBase'] * ($premiumRate / 100) / 2);


    return $share;

    I tried using:
    ->select(array("EmployeeShare", "Employee"), array("EmployerShare", "Employer), "SalaryBase")

    but above didn't work.

  • HarroHarro
    Accepted Answer
    With a column alias you mean "SELECT a AS b"?

    Remember that the ORM is not a query builder, if you omit columns from the result, or worse, rename columns, the result is unpredictable as when it hydrates the raw result it won't be able to map the result back to the ORM's record properties.

    Furthermore, the ORM already uses column aliasing, so you can't add your own.

    If you want to use custom queries, use DB::query() instead.
  • Yes, I'm using DB::query() now.


Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion