Welcome Guest, Not a member yet? Register   Sign In
Extending model
#1

I found an interesting scenario and please help me to see whether it is an issue.
I defined the table as following:
Table:t_orderinfo

Columns:
id
int AI PK
order_id
varchar(100) PK
payment_status int
company_id varchar(100)
payment_amount  decimal(10,2)
create_time datetime
update_time datetime

And I defined my entity
class Order extends Entity
{
    protected $attributes = [
        'order_id' => null,       // Represents a username
        'company_id' => null,
        'payment_amount' => null,
        'payment_status' => null
    ];
}


And my Model

class OrderModel extends Model
{
    protected $DBGroup = 'default';
    protected $table      = 't_orderinfo';
    protected $primaryKey = 'id';
    protected $returnType    = 'App\Entities\Order';
    protected $useSoftDeletes = false;

    protected $allowedFields = [
        'order_id'
        'payment_status',
        'company_id',
        'payment_amount'
    ];

    protected $useTimestamps = true;
    protected $createdField  = 'create_time';
    protected $updatedField  = 'update_time';

    protected $validationRules    = [];
    protected $validationMessages = [];
    protected $skipValidation     = false;
}

And wired thing is , when set the primaryKey as id, I can successfully save the record, but when I use order_id as my PK, the save method also return true, but there is no record in the database.

Is there anyone can support me?
Reply


Messages In This Thread
Extending model - by windyboy911 - 03-31-2020, 09:11 PM
RE: Extending model - by jreklund - 04-01-2020, 10:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB