Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

thinkphp 模型关联一对一排序

`{

"code": 1,
"msg": "操作成功",
"data": {
    "list": [{
        "id": 55,
        "group_id": 3,
        "username": "1142843053",
        "nickname": "1142843053",
        "status": 1,
        "userData": {
            "id": 54,
            "login_times": 2,
            "last_login_ip": "118.114.13.254",
            "create_ip": "118.114.13.254",
            "last_login_time": "2020-10-15 22:48:31",
            "create_time": "2020-10-15 22:45:04",
            "uid": 55,
            "head_img": "",
            "isvip": 0,
            "expritime": ""
        },
        "alphaID": "Taaaab"
    }, {
        "id": 54,
        "group_id": 3,
        "username": "2105338330",
        "nickname": "2105338330",
        "status": 1,
        "userData": {
            "id": 53,
            "login_times": 1,
            "last_login_ip": "117.174.79.254",
            "create_ip": "117.174.79.254",
            "last_login_time": "",
            "create_time": "2020-10-15 21:36:00",
            "uid": 54,
            "head_img": "",
            "isvip": 0,
            "expritime": ""
        },
        "alphaID": "Saaaab"
    }, {
        "id": 53,
        "group_id": 3,
        "username": "483487396",
        "nickname": "483487396",
        "status": 1,
        "userData": {
            "id": 52,
            "login_times": 1,
            "last_login_ip": "42.102.242.135",
            "create_ip": "42.102.242.135",
            "last_login_time": "",
            "create_time": "2020-10-15 15:54:16",
            "uid": 53,
            "head_img": "",
            "isvip": 0,
            "expritime": ""
        },
        "alphaID": "Raaaab"
    }],
    "count": 39,
}

}`

以上是数据

用户表 user 用户对应的数据表 userdata

thinkphp框架在model里面hasone关联了
` public function userData()

{
    return $this->hasOne('userdata', 'uid', 'id');
}`

业务层怎么根据userdata里面的数据排序

比如怎么根据 create_time创建时间排序呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

用hasWhere 闭包查询


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...