-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from ysfks/latest
Add condition to skip retrieving models that are not cascadable
- Loading branch information
Showing
7 changed files
with
113 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,6 @@ tests/logs | |
build/ | ||
|
||
# PhpStorm | ||
.idea | ||
.idea | ||
|
||
.phpunit.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Askedio\SoftCascade\Traits; | ||
|
||
trait ChecksCascading | ||
{ | ||
/** | ||
* Check if the model is enabled to cascade. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $model | ||
* | ||
* @return bool | ||
*/ | ||
protected function hasCascadingRelations($model): bool | ||
{ | ||
return method_exists($model, 'getSoftCascade'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Askedio\Tests\App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Record extends Model | ||
{ | ||
public $primaryKey = null; | ||
|
||
public $timestamps = false; | ||
|
||
public $incrementing = false; | ||
|
||
protected $table = 'records'; | ||
|
||
protected $fillable = ['record_id', 'time', 'value']; | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/App/database/migrations/2024_10_23_095215_create_records_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
|
||
class CreateRecordsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
DB::connection()->getSchemaBuilder()->create('records', function (Blueprint $table) { | ||
$table->string('record_id'); | ||
$table->float('value'); | ||
$table->timestamp('time'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
DB::connection()->getSchemaBuilder()->dropIfExists('records'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters