HasanCseBuet
HasanCseBuet

Reputation: 108

How to return a value using Doctrine in symfony 1.4?

I want to return Leave Type of an employee in a particular date using the following function

public static function getLeaveTypeInDate($date, $empId) {
    $leaveType = Doctrine_Query::create()
            ->select('leave_type')
            ->from('EmployeeLeave')
            ->where('employee_id = ?', $empId)
            ->andWhere('applied_from = ?', $date)
            ->execute();

    return $leaveType[0];

But it returns Employee Name which is not directly stored in "employee_leave" table.

Upvotes: 0

Views: 63

Answers (1)

ilSavo
ilSavo

Reputation: 854

In this moment you're returning an entire EmployeeLeave object by doing ->execute() and then return $leaveType[0]

My advice is to change your query statement by replacing ->execute() with ->fetchOne()

Then, instead of doing return $leaveType[0] you could simply do return $leaveType->getLeaveType()

Upvotes: 1

Related Questions