# afterSave event in associated table

**URL:** <https://discourse.cakephp.org/t/aftersave-event-in-associated-table/3304>\
**Category:** Need Help\
**Created:** [October 4, 2017, 5:10am UTC](https://discourse.cakephp.org/t/aftersave-event-in-associated-table/3304 "2017-10-04T05:10:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayoeng](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ayoeng/32/1486_2.png) [@ayoeng](https://discourse.cakephp.org/u/ayoeng)\
**Post date:** [October 4, 2017, 5:10am UTC](https://discourse.cakephp.org/t/aftersave-event-in-associated-table/3304/1 "2017-10-04T05:10:47Z")

</div>

Hi,  
It’s a basic question. I think I misunderstood when I read about Lifecycle Callbacks.

I have two tables: orders and items.

```
// OrdersTable.php
$this->table('orders');
$this->displayField('id');
$this->primaryKey('id');

$this->hasMany('Items', [
    'foreignKey' => 'order_id',
    'saveStrategy' => 'replace',
    'dependent' => true,
    'joinType' => 'INNER',
]);

// ItemsTable.php
$this->table('items');
$this->displayField('id');
$this->primaryKey('id');

$this->belongsTo('Orders', [
    'foreignKey' => 'order_id',
    'joinType' => 'INNER'
]);

```

Items are being inserted and deleted correctly, but since I want to record inventory exits, I had planned to use the afterSave and afterDelete events in ItemsTable. But it’s not working.

I can not access these events from an associated table?

Thanks for any advice.

---

<div class="post-metadata">

**Author:** ![xaphalanx](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/xaphalanx/32/575_2.png) [@xaphalanx](https://discourse.cakephp.org/u/xaphalanx)\
**Post date:** [October 13, 2017, 8:54pm UTC](https://discourse.cakephp.org/t/aftersave-event-in-associated-table/3304/2 "2017-10-13T20:54:13Z")

</div>

Not unless you are saving to that table.

---

<div class="post-metadata">

**Author:** ![ayoeng](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ayoeng/32/1486_2.png) [@ayoeng](https://discourse.cakephp.org/u/ayoeng)\
**Post date:** [October 14, 2017, 5:09am UTC](https://discourse.cakephp.org/t/aftersave-event-in-associated-table/3304/3 "2017-10-14T05:09:16Z")

</div>

I’m trying another way.  
Thanks for the answer.
