Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue on save json field (array) #231

Open
chiendv opened this issue Jan 14, 2022 · 2 comments
Open

issue on save json field (array) #231

chiendv opened this issue Jan 14, 2022 · 2 comments
Labels

Comments

@chiendv
Copy link

chiendv commented Jan 14, 2022

Hello,

I using reliese version 1.1.3. When I tried to save record on this model what I get in field "params" is json value of whole record included "params" inside liked bellow

model define

use Reliese\Database\Eloquent\Model;

class CourseAutomation extends Model

	protected $casts = [
                  ...
		'params' => 'array' //this is json field
                ...
	];
	protected $fillable = [
		...
		'params',
		...
	];
}

save record

$record = CourseAutomation::firstOrFail(16);
$data['params'] = ["check_days_value" => "2", "check_days_type" => "month"];
$record->update($data);

data was saved

but here is what I got in database:

{
    "id": 16,
    "course_id": 3,
    "start_at": 0,
    "end_at": 15,
    "child_days": 60,
    "compare": "days",
    "title": "...",
    "content": "...",
    "created_at": "2022-01-11 20:44:17",
    "updated_at": "2022-01-14 16:58:26",
    "section": false,
    "notify": false,
    "chat": false,
    "remind": true,
    "params": {
        "id": 16,
        "course_id": 3,
        "start_at": 0,
        "end_at": 15,
        "child_days": 60,
        "compare": "days",
        "title": "...",
        "content": "...",
        "created_at": "2022-01-11 20:44:17",
        "updated_at": "2022-01-14 16:58:00",
        "section": false,
        "notify": false,
        "chat": false,
        "remind": true,
        "params": {
            "check_days_value": "2",
            "check_days_type": "month"
        },
        "status": true
    },
    "status": true
}

When I change extends of model to Illuminate\Database\Eloquent\Model it working fine.

Hope it could be fine with reliese in next version.

@finiteinfinity
Copy link
Contributor

Hi @chiendv,

Try changing the cast to object rather than array

protected $casts = [
    ...
    'params' => 'object' //this is json field
    ...
];

The issue has been reported a few times, here and here but I've yet to look at what the underlying cause is.

Hope this helps.

@CristianLlanos
Copy link
Member

I'm sorry for writing this, but it is not advised to use Reliese\Database\Eloquent\Model; please use Illuminate\Database\Eloquent\Model instead. The former was a proof of concept for an old version of Laravel and unfortunately was not fully tested. It was removed from the default configurations and it should be deprecated. Once again, I'm sorry for the inconvenience it may have caused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants