laravel19
一、联表查询
①创建迁移文件
#php artisan make:migration create_article_table
#php artisan make:migration create_author_table
②相继编写2个迁移文件的代码
③执行生成数据表的迁移文件
#php artisan migrate
④模拟数据(通过填充器来实现)
a. 创建填充器文件(可以将多个数据表的写入操作写在一起)
#php artisan make:seeder ArticleAndAuthorTableSeeder
b. 编写数据模拟的代码
提示:填充器的模拟数据,可以参考“文件”文件夹中的数据。
c. 需要执行填充器文件
#php artisan db:seed --class=ArticleAndAuthorTableSeeder
联表查询一共有:内连接(inner)、左连接(left)、右连接(right)。
原始的sql语句:【左外连接】
表:文章表(article)主 t1、作者表(author)从 t2
关联关系:t1.author_id = t2.id
原生的sql:select t1.id,t1.article_name,from article as t1 left join author as t2 on t1.author_id= t2.id;
或者:select article.id,article.article_name,author.author_name from article left join author on article.author_id= author.id;
将上述的sql语句改成链式操作:
语法:DB门面 -> join联表方式名称小驼峰写法(关联的表名,表1的字段,运算符,表2的字段)