Skip to content

Commit 15961bf

Browse files
authored
Merge pull request #93 from siamak2/master
register saved event listener in bootMetable
2 parents 74d5aab + 358027a commit 15961bf

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/Kodeine/Metable/Metable.php

+7-18
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
trait Metable
1111
{
12-
13-
// Static property registration sigleton for save observation and slow large set hotfix
14-
public static $_isObserverRegistered;
12+
1513
public static $_columnNames;
1614

1715
/**
@@ -194,20 +192,6 @@ public function whereMeta($key, $value)
194192
->get();
195193
}
196194

197-
/**
198-
* Trait specific functions
199-
* -------------------------.
200-
*/
201-
protected function setObserver()
202-
{
203-
if(!isset(self::$_isObserverRegistered)) {
204-
$this->saved(function ($model) {
205-
$model->saveMeta();
206-
});
207-
self::$_isObserverRegistered = true;
208-
}
209-
}
210-
211195
protected function getModelStub()
212196
{
213197
// get new meta model instance
@@ -244,7 +228,6 @@ protected function saveMeta()
244228
protected function getMetaData()
245229
{
246230
if (!isset($this->metaLoaded)) {
247-
$this->setObserver();
248231

249232
if ($this->exists) {
250233
$objects = $this->metas
@@ -364,6 +347,12 @@ public function hasColumn($column) {
364347
if(empty(self::$_columnNames)) self::$_columnNames = array_map('strtolower',\Schema::connection($this->getConnectionName())->getColumnListing($this->getTable()));
365348
return in_array(strtolower($column), self::$_columnNames);
366349
}
350+
351+
public static function bootMetable(){
352+
static::saved(function ($model) {
353+
$model->saveMeta();
354+
});
355+
}
367356

368357
public function __unset($key)
369358
{

0 commit comments

Comments
 (0)