fastadmin notes

 

1. The usage of belongsTo and hasone

When using the ORM of the model, belongsTo and hasOne both show a one-to-one relationship, but the two are not the same. The following example illustrates the difference between the two: 
first there is the user table field id name password field 
and then the user_address table id user_id city field

Use hasOne when associating the user_address table in the User model, because there is no foreign key that associates the two tables in the user table

Use belongsTo when associating the user table in the UserAddress model, because there is a foreign key user_id that associates the two tables in the user_address table

That is, whoever holds the foreign key, write belongsTo in the model

2. What if you need to filter fields?

   If belongsTo() is used in the model, it is not possible to filter by field in the model, but in the controller, filter when pre-associated with ->with, as shown in the figure:

   $list = $sto->where($where)
               ->with([
                        'dianpu' => function ($query) {
                            $query->withField('id,name');
                        },
                    
                    ])

But the hasone of the model can directly use the field:

 public function profile()
    {
        return $this->hasOne('Profile')->field('id,name,email');
    }

 

 

3. Use document one-to-one related query, no results when searching

Answer: It is recommended that you use supplier.id directly, and then use formatter to return the data of supplier.name, such as

{field:'suppelier.id', title:'名称', formatter:(value, row, index){return row.supperlier.name;}}

 5. In the TP template, select judgment:

   <select  id="c-dianpu" class="form-control selectpicker" name="row[dianpu]">
                {foreach name="FaultgradeList" item="vo"}
                    <option value="{$vo.id}" {in name="$vo.id" value="$row.dianpu"}selected{/in}>{$vo.name}</option>
                {/foreach}
            </select>

Among them, name is the ID of the loop, and value is the value passed. When the ID key value of the loop is equal to the passed $row.dianpu, the key is selected and displayed as the value of the current key

 

6. How to define that only one window can pop up at a time

To a property on the Add button  data-id="add" OR data-id="edit" to

Guess you like

Origin blog.csdn.net/EasyTure/article/details/109337345