Laravel有多个中间表

时间:2016-07-02 14:55:40

标签: laravel eloquent

我正在尝试开发多店电子商务平台。 所以创建了以下表格:

#
#Fri Jul 01 12:46:38 CEST 2016
codename1.arg.java.version=8
codename1.ios.appid=Q5GHSKAL2F.com.duus.levabo
codename1.ios.release.provision=
codename1.arg.rim.obfuscation=false
codename1.arg.ios.newStorageLocation=true
codename1.j2me.nativeTheme=nbproject/nativej2me.res
codename1.arg.ios.project_type=ios
codename1.arg.ios.interface_orientation=UIInterfaceOrientationPortrait\:UIInterfaceOrientationPortraitUpsideDown\:UIInterfaceOrientationLandscapeLeft\:UIInterfaceOrientationLandscapeRight
codename1.displayName=Levabo
codename1.android.keystoreAlias=
codename1.arg.windows.makeReleaseAppxbundle=true
codename1.ios.release.certificate=
codename1.android.keystorePassword=
codename1.ios.provision=
codename1.arg.android.release=true
codename1.arg.ios.dsym=false
codename1.arg.ios.statusbar_hidden=false
codename1.arg.windows.buildType=Release
codename1.languageLevel=5
codename1.android.keystore=
codename1.vendor=DuusPartnersPS
codename1.arg.win.ver=8
codename1.ios.certificatePassword=
codename1.ios.debug.certificatePassword=
codename1.mainName=MainForm
codename1.windows.certificatePassword=password
codename1.ios.release.certificatePassword=
codename1.arg.ios.prerendered_icon=false
codename1.ios.debug.certificate=
libVersion=116
codename1.arg.ios.application_exits=false
codename1.secondaryTitle=CodenameOne_Template
codename1.description=
codename1.ios.debug.provision=
codename1.arg.j2me.nativeThemeConst=0
codename1.rim.certificatePassword=
codename1.version=1.0
codename1.ios.certificate=
codename1.arg.windows.platforms=x86|x64|ARM
codename1.windows.certificate=/Users/thomaswix/Keychain_1.pfx
codename1.icon=icon.png
codename1.arg.windows.appid=DuusPartnersPS.Levabo
codename1.rim.signtoolCsk=
codename1.arg.android.debug=false
codename1.rim.signtoolDb=
codename1.arg.ios.testFlight=false
codename1.arg.ios.includePush=false
codename1.packageName=DuusPartnersPS.Levabo

这是我模特关系的总结:

  • 商店>产品:购买hasMany产品
  • 产品 - >商店:产品属于商店
  • 订单 - >详细信息:订单hasMany OrderDetail
  • 订单详情 - >订单:订单详情属于订单
  • 订单详情 - >产品:订单详情属于产品
  • 产品 - >订单:产品有多个订单详细信息

现在, 1:是否可以定义 Shop->订单关系?(由于多个中间件,在这种情况下,由于多个中间件,因此接缝无法使用表)

2:如果可能, shop-> orders->详细信息是否只包含与商店产品相关的记录?

应该注意的是,每个订单可能包含来自多个商店的产品,但 shop-&gt;订单 - &gt;详细信息关系应仅包含商店产品。 < / p>

1 个答案:

答案 0 :(得分:0)

在这种情况下没有本机关系。

我创建了class Shop extends Model { use \Staudenmeir\EloquentHasManyDeep\HasRelationships; public function orders() { return $this->hasManyDeep(Order::class, [Product::class, 'order_details']); } } 关系,并支持import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL11; public class Main { public static void main(String[] args) { if (!GLFW.glfwInit()) { throw new RuntimeException("glfwInit"); } long monitor = GLFW.glfwGetPrimaryMonitor(); GLFWVidMode.Buffer videoModeBuffer = GLFW.glfwGetVideoModes(monitor); GLFWVidMode mode = videoModeBuffer.get(videoModeBuffer.limit() - 1); long window = GLFW.glfwCreateWindow( mode.width(), mode.height(), "Window", monitor, 0L); GLFW.glfwMakeContextCurrent(window); GLFW.glfwSwapInterval(1); GL.createCapabilities(); GL11.glClearColor(1, 1, 1, 1); while (!GLFW.glfwWindowShouldClose(window)) { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GLFW.glfwSwapBuffers(window); GLFW.glfwPollEvents(); } GLFW.glfwTerminate(); } } Repository on GitHub

安装后,您可以像这样使用它:

WITH tab AS (
SELECT DISTINCT W1.COMPANY_NAME, 
       E1.CITY
  FROM EMPLOYEE E1
  JOIN WORKS W1 ON (E1.firstname = W1.firstname AND E1.lastname = W1.lastname)
 WHERE E1.CITY IN (SELECT DISTINCT E2.CITY
                     FROM EMPLOYEE E2,WORKS W2 
                    WHERE E2.firstname = W2.firstname
                      AND E2.lastname = W2.lastname 
                      AND W2.COMPANY_NAME= 'Mutual of Omaha')
)
SELECT tab.COMPANY_NAME
  FROM tab 
 GROUP BY tab.COMPANY_NAME
HAVING COUNT(tab.CITY) = (SELECT COUNT(sub.CITY) FROM tab sub WHERE COMPANY_NAME = 'Mutual of Omaha')