Ticket #1363 (closed defect: fixed)

Opened 11 months ago

Last modified 10 months ago

$event->getInvoker() returning incorrect object on a relation (reference object)

Reported by: killroyboy Owned by: romanb
Priority: critical Milestone:
Component: Listeners Version: 1.0.0
Severity: Keywords:
Cc: Has Test: no
Status: Pending Core Response Has Patch: yes

Description

I have a listener that I've attached to several of my table objects. It uses the $event->getInvoker() to determine who called it, but it isn't work as expected.

When the object is instantiated normally, it works just fine, but when it is a reference within another object, it doesn't work quite right.

In relation to the below example, if I query based on the Invoice object, the $event->_invoker inside of DateFormatListener? is set to Invoice rather than LineItem?.

I've attached a patch to fix this, but I'm not sure it's complete. It works for me.

class Invoice extends BaseInvoice {
  public function setUp() {
    $this->hasMany('LineItem as lines', array('local' => 'id', 'foreign' => 'invoice_id')
  }
}


class LineItem extends BaseLineItem {
  public function setUp() {
    $this->addListener(new DateFormatListener());
  }
}

class DateFormatListener extends Doctrine_Record_Listener {
  public function preHydrate(Doctrine_Event $event) {
    if ($event->getInvoker()->tableName == 'line_item') {
      // format my dates
    } else {
      // do something else
    }
  }
}

Attachments

invoker.patch (503 bytes) - added by killroyboy 11 months ago.
call $event->setInvoker($event) for reference objects as well

Change History

Changed 11 months ago by killroyboy

call $event->setInvoker($event) for reference objects as well

Changed 11 months ago by killroyboy

  • version changed from 0.11 to 1.0

Forgot to mention the patch was created against tags/1.0.0-BETA1

Changed 10 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [4831]) fixes #1363

Changed 10 months ago by jwage

  • milestone changed from Unknown to 1.0.0-RC2

Changed 10 months ago by anonymous

  • milestone New deleted

Milestone New deleted

Note: See TracTickets for help on using tickets.