Ticket #1363 (closed defect: fixed)
$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
Change History
Note: See
TracTickets for help on using
tickets.