Skip to content

Commit

Permalink
remove breaking change: casts support
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed Feb 5, 2024
1 parent b0fb1e2 commit 20aad4e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
13 changes: 3 additions & 10 deletions src/Sushi.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,9 @@ public function migrate()
$this->createTableWithNoData($tableName);
}

if (count($this->casts) > 0) {
foreach ($rows as $row) {
// If $casts are present, use Eloquent's "create" instead of a plain insert so they are used and applied...
static::forceCreate($row);
}
} else {
foreach (array_chunk($rows, $this->getSushiInsertChunkSize()) ?? [] as $inserts) {
if (! empty($inserts)) {
static::insert($inserts);
}
foreach (array_chunk($rows, $this->getSushiInsertChunkSize()) ?? [] as $inserts) {
if (! empty($inserts)) {
static::insert($inserts);
}
}
}
Expand Down
24 changes: 0 additions & 24 deletions tests/SushiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ function columns_with_varying_types()
$this->assertEquals(null, $row->null);
}

/** @test */
function model_with_casts()
{
$model = ModelWithCasts::first();

$this->assertTrue(is_array($model->is_array));
$this->assertTrue(is_bool($model->is_boolean));
}

/** @test */
function model_with_custom_schema()
{
Expand Down Expand Up @@ -382,18 +373,3 @@ public function maki()
return $this->belongsTo(Maki::class);
}
}


class ModelWithCasts extends Model
{
use \Sushi\Sushi;

protected $casts = [
'is_array' => 'array',
'is_boolean' => 'boolean',
];

protected $rows = [
['is_array' => [1, 2, 3], 'is_boolean' => true],
];
}

0 comments on commit 20aad4e

Please sign in to comment.