我需要让Laravel雄辩地为两个表实现内连接
import java.lang
import org.apache.flink.streaming.api.functions.windowing.WindowFunction
import org.apache.flink.streaming.api.scala._
import org.apache.flink.streaming.api.windowing.assigners.SlidingProcessingTimeWindows
import org.apache.flink.streaming.api.windowing.time.Time
import org.apache.flink.streaming.api.windowing.windows.TimeWindow
import org.apache.flink.util.Collector
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
答案 0 :(得分:2)
您可以使用laravel inner join DB
$result = DB::table("materials as m")
->join("material_lists as ml","ml.id","=","m.material_id")
->join("colors as c","c.id","=","m.color_id")
->where('m.carpet_id',2)
->select("m.id",
"ml.name", "ml.cost",
"c.code", "c.hex", "c.name",
"m.color_cost", "m.estimation", "m.remarks")
->get();
如果你做的话,分享你的模特和关系。
答案 1 :(得分:1)
如果您想使用Eloquent,那么您应该:
在材质模型类中,您应该具有一对多的类型关系:
public function MaterialsList {
return $this->haveMany ('MatrialLists_ModelName')
}
和MaterialsLists模型类中相反的'belongsTo'类型关系。
public function Materials {
return $this->belongsTo ('Materials_ModelName')
}
3。您可以从Materials对象中引用MaterialsList对象属性,如下所示:
$materialsListCollection = $materials ->MaterialsLists->all();
其中$ materials是材料模型的实例。
如果Eloquent不是强制性的,那么您可以使用Query Builder中的连接方法,使用DB facade这样的方法:
$collection = DB::table('materials')
join('material_lists' , 'materials.id' , '=','material_lists,id') ->
join('colors' , 'colors.id' , '=','materials.colors,id') ->
select ('materials.id', 'material_lists.name', 'material_lists.cost',
'colors.code', 'colors.hex', 'colors.name' 'materials.color_cost',
'materials.estimation', 'materials.remarks')
->where('carpet_id' , '2')->get()
希望有所帮助:)