Eloquent ORM 查询数据的关联扩展
程序员文章站
2023-12-28 22:59:28
...
user [{ id: 1, name: "jack", age: "22", city_id: 1, job_id: 1 }, { id: 2, name: "yoyo", age: "22", city_id: 2, job_id: 2 }]; city [{ id: 1, name: "beijin" }, { id: 2, name: "shanghai" }]
单独查询表的结果是这样的,我想实现类似下面的扩展结果要怎么操作,看了api文档还是不太明白
user [{ id: 1, name: "jack", age: "22", city: {id: 1, name: "beijin"}, job_id: {id:1, name: "dev"} }, { id: 2, name: "yoyo", age: "22", city: {id: 2, name: "shanghai"}, job: {id: 2, name: "art"} }];
回复内容:
user [{ id: 1, name: "jack", age: "22", city_id: 1, job_id: 1 }, { id: 2, name: "yoyo", age: "22", city_id: 2, job_id: 2 }]; city [{ id: 1, name: "beijin" }, { id: 2, name: "shanghai" }]
单独查询表的结果是这样的,我想实现类似下面的扩展结果要怎么操作,看了api文档还是不太明白
user [{ id: 1, name: "jack", age: "22", city: {id: 1, name: "beijin"}, job_id: {id:1, name: "dev"} }, { id: 2, name: "yoyo", age: "22", city: {id: 2, name: "shanghai"}, job: {id: 2, name: "art"} }];
推荐阅读
-
Eloquent ORM 查询数据的关联扩展
-
在oracle 数据库查询的select 查询字段中关联其他表的方法
-
Laravel框架Eloquent ORM简介、模型建立及查询数据操作详解
-
laravel框架数据库操作、查询构建器、Eloquent ORM操作实例分析
-
在oracle 数据库查询的select 查询字段中关联其他表的方法
-
Laravel框架Eloquent ORM简介、模型建立及查询数据操作详解
-
Django视图之ORM数据库查询操作API的实例
-
laravel框架数据库操作、查询构建器、Eloquent ORM操作实例分析
-
MySQL 多表关联一对多查询实现取最新一条数据的方法示例
-
oracle数据库的同义词Synonym与dblink关联,从而可以直接查询远程数据库的表,不用指定用户和@指定dblink名称