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

There is a issue on soft deleting . #10487

Closed
01Tuner opened this issue Oct 5, 2015 · 5 comments
Closed

There is a issue on soft deleting . #10487

01Tuner opened this issue Oct 5, 2015 · 5 comments

Comments

@01Tuner
Copy link

01Tuner commented Oct 5, 2015

customer model

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Customer extends Model
{
    use SoftDeletes;

    protected $fillable  = ['name','place','address'];

    protected $dates = ['deleted_at','created_at','updated_at','amc_date'];

    protected $appends = ['amc_or_not','active_or_not','voice_or_not'];


    public function User()
    {
        return $this->hasMany('User');
    }    

    public function Student()
    {
        return $this->hasManyThrough('Student','User');
    }

user model

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Database\Eloquent\SoftDeletes;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
    use Authenticatable, CanResetPassword;

    use SoftDeletes;

    protected $table = 'users';


    protected $fillable = ['name', 'email', 'password','mobno','type','active'];

    protected $hidden = ['password', 'remember_token'];

    protected $dates = ['deleted_at'];

    protected $appends = ['usertype'];

    public function Customer()
    {
        return $this->belongsTo('SmSPortal\Customer');
    }

student model


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Student extends Model
{
    use SoftDeletes;

    protected $table = 'studentsdata';

    protected $dates = ['deleted_at','created_at','updated_at'];

    protected $fillable = ['admno','name','mobno'];
}

when i perform this query

$delete = Customer::find($this->customer_id)->Student()->delete();

i get the following error

QueryException in Connection.php line 636:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'updated_at' in field list is ambiguous (SQL: update `studentsdata` inner join `users` on `users`.`id` = `studentsdata`.`user_id` set `studentsdata`.`deleted_at` = 2015-10-05 10:46:56, `updated_at` = 2015-10-05 10:46:56 where `studentsdata`.`deleted_at` is null and `users`.`deleted_at` is null and `users`.`customer_id` = 2)
@safoorsafdar
Copy link

It's look like, query get confuse to select specific table column update_at, all table contain this column, so you have to define table name if we talk about custom query tableName.update_at
I also face this issue already.

@01Tuner
Copy link
Author

01Tuner commented Oct 6, 2015

this is not a solution .its a bug of laravel eloquent.
can say how to fix it ??

@baoanhng
Copy link

baoanhng commented Oct 12, 2016

@GrahamCampbell Isn't this a bug, but you just closed it without providing some reasons, Are there other ways around?

@themsaid
Copy link
Member

@trandaihung check #13909 it's a duplicate.

@joseevillasmil
Copy link

use the functions has, withHas and doestnhave, these functions are used to join with the propeties of the models.

https://laraveldaily.com/eloquent-doesnthave-get-rows-children/

https://laravel.com/docs/5.8/eloquent-relationships#querying-relationship-existence

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

No branches or pull requests

6 participants