Welcome Guest, Not a member yet? Register   Sign In
Add new option for make:model for specific table
#1

Usually, after building the model, I have to add the names of the fields to $allowedFields.This is time-consuming for me.

I don't know exactly whether other developers have experienced this issue or not.

I suggest to add a new option to command php spark make:modelfor this issue.

Option -for takes the name of the table and adds the fields to $allowedFields
to generate the model.

I think this option helps a lot in saving the developer's time.

Code:
Data of Table "sms_sender":

+----+--------------+------+------+----+---------------+--------+------------+------------+------------+
| id | message_text | type | from | to | send_datetime | status | created_at | updated_at | deleted_at |
+----+--------------+------+------+----+---------------+--------+------------+------------+------------+


Code:
php spark make:model -for sms_sender

PHP Code:
    protected $DBGroup          'default';
    protected $table            'sms_sender';
    protected $primaryKey      'id';
    protected $useAutoIncrement true;
    protected $returnType      'array';
    protected $useSoftDeletes  true;
    protected $protectFields    true;
    protected $allowedFields    = [
        'message_text',
        'type',
        'from',
        'to',
        'send_datetime',
        'status'
    ]; 
Reply
#2

I like this idea.
Reply
#3

No problem. Good idea!
Reply
#4

I agree. I myself had tables of the type date_1, date_N... When creating, it is important to take into account the primary key
Reply
#5

Yes, good idea but somefields will not need to be in allowFields.

So we will need to look into that.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

i agree too @datamweb
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#7

(07-27-2023, 10:35 PM)InsiteFX Wrote: Yes, good idea but somefields will not need to be in allowFields.

So we will need to look into that.
For example? Default dates can be added (created_at, etc). ID as the `id` field to ignore. There is a problem if the ID is of a different type (`product_id`). Then you need to request it from the console. After creating the model, remind the developer to check these fields
Reply
#8

ID and timestamps are not needed in $allowedFields.
Reply
#9

I also agree that it's a good idea.
Reply
#10

The option --table was implemented.

Code:
$ php spark make:model --help

CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-01 02:59:10 UTC+00:00

Usage:
  make:model <name> [options]

Description:
  Generates a new model file.

Arguments:
  name  The model class name.

Options:
  --table      Supply a table name. Default: "the lowercased plural of the class name".
  --dbgroup    Database group to use. Default: "default".
  --return    Return type, Options: [array, object, entity]. Default: "array".
  --namespace  Set root namespace. Default: "APP_NAMESPACE".
  --suffix    Append the component title to the class name (e.g. User => UserModel).
  --force      Force overwrite existing file.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB