mysql - larval ORM 模型使用find方法無(wú)法準(zhǔn)確的查找到對(duì)應(yīng)的數(shù)據(jù)
問題描述
mysql 數(shù)據(jù)表主鍵Order_ID為bigint(20),使用Order模型查找對(duì)應(yīng)的訂單卻找到了其他的訂單。比如:Order:find(20170214006401),卻查找到Order_ID為20161009000577的訂單.調(diào)用代碼如下:<?php$rsOrder = Order::find(20170214006401)->first()->toArray();?>
Order模型如下<?phpuse IlluminateDatabaseEloquentSoftDeletes;
class Order extends IlluminateDatabaseEloquentModel {
use SoftDeletes;protected $dates = [’deleted_at’];//protected $fillable = [’Order_Status’];protected $fillable = array(’Order_Status’,’Is_withdraw’,’Withdraw_Time’);protected $primaryKey = 'Order_ID';protected $table = 'user_order';public $timestamps = false;// 多wherepublic function scopeMultiwhere($query, $arr) { if (!is_array($arr)) {return $query; } foreach ($arr as $key => $value) {$query = $query->where($key, $value); } return $query;}
//無(wú)需日期轉(zhuǎn)換
public function getDates() { return array();}/** * 指定時(shí)間內(nèi)的訂單 * @param $Users_ID 店鋪唯一標(biāo)識(shí) * @param $Begin_Time 開始時(shí)間 * @param $End_Time 結(jié)束時(shí)間 * @return array 訂單列表 */public function ordersBetween($Users_ID, $Begin_Time, $End_Time, $Order_Status) { $builder = $this::where(’Users_ID’, $Users_ID); if ($Order_Status != ’all’) {$builder = $builder->where(’Order_Status’, $Order_Status); }$builder->whereBetween(’Order_CreateTime’, [$Begin_Time, $End_Time])->orderBy(’Order_CreateTime’, ’desc’); return $builder;}
}
問題解答
回答1:代碼來自:/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php
public function find($id, $columns = [’*’]) {return $this->where(’id’, ’=’, $id)->first($columns); }
find方法好像默認(rèn)為id為主鍵進(jìn)行查找的
回答2:find方法默認(rèn)搜索的是主鍵
相關(guān)文章:
1. macos - 無(wú)法source activate python272. 我在導(dǎo)入模板資源時(shí)遇到無(wú)法顯示的問題,請(qǐng)老師解答下3. MySQL中無(wú)法修改字段名的疑問4. css3 讓圖片變成灰色(filter),但針對(duì)IE11瀏覽器無(wú)效5. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?6. html5 - 前端面試碰到了一個(gè)緩存數(shù)據(jù)的問題,來論壇上請(qǐng)教一下7. PHPExcel表格導(dǎo)入數(shù)據(jù)庫(kù)怎么導(dǎo)入8. html - 網(wǎng)頁(yè)的a標(biāo)簽到底要不要寫上域名?9. css - 移動(dòng)端 盒子內(nèi)加overflow-y:scroll后 字體會(huì)變大10. javascript - react如何獲取offsetX?

網(wǎng)公網(wǎng)安備