一张桌子有多个枢轴表

时间:2017-09-16 10:19:51

标签: mysql laravel laravel-5.2

这些是我模特中的关系:

  • Medecine属于许多药理学和药理学属于许多Medecine
  • Medecine属于许多治疗和治疗属于许多Medecine
  • Medecine属于许多Galenic和Galenic属于许多Medecine
  • Medecine属于许多AdministrationMode和AdministrationMode属于许多Medecine
  • Medecine属于许多ActivePrinciple和ActivePrinciple属于许多Medecine

药理学在所有情况下运作良好且速度更快(loadind是正常的) - :)

当我在我的控制器中为其他关系执行此类查询时,我的问题就在那里:

$Pharmacologic = Pharmacologic ::Find(1);

$Medecines= $Pharmacologic ->medecines()->orderBy('field1', 'asc')
->paginate(10);

return view('page', compact('Medecines'));

迁移

  1. 药理和医学支点
  2. Schema::create('pharmaco_medecine', function(Blueprint $table) {
    $table->increments('id');
    $table->integer('medecine _id')->unsigned(); $table->foreign('medecine _id') ->references('id')->on('tbl_medecine') ->onDelete('cascade');
    $table->integer('pharmaco_id')->unsigned(); $table->foreign('pharmaco_id') ->references('id')->on('tbl_pharmaco') ->onDelete('cascade'); });
    
    1. 治疗和医学支点
    2. Schema::create('therapeutic_medecine', function(Blueprint $table) {
      
      $table->increments('id');
      
      $table->integer('medecine_id')->unsigned();
      $table->foreign('medecine_id')
            ->references('id')->on('tbl_medecine')
            ->onDelete('cascade');
      
      $table->integer('therapeutic_id')->unsigned();
      $table->foreign('therapeutic_id')
            ->references('id')->on('tbl_therapeutic')
            ->onDelete('cascade');
      
      });
      
      1. Galenic and medecine pivot
      2. Schema::create('gal_medecine, function(Blueprint $table) {
        
        $table->increments('id');
        
        $table->integer('medecine_id')->unsigned();
        $table->foreign('medecine_id')
              ->references('id')->on('tbl_medecine')
              ->onDelete('cascade');
        
        $table->integer('gal_id')->unsigned();
        $table->foreign('gal_id')
              ->references('id')->on('tbl_gal')
              ->onDelete('cascade');
        
        });
        
        1. AdministrationMode和medecine pivot
        2. Schema::create('medecine_admin_mode', function(Blueprint $table) {
          
          $table->increments('id');
          
          $table->integer('medecine_id')->unsigned();
          $table->foreign('medecine_id')
                ->references('id')->on('tbl_medecine')
                ->onDelete('cascade');
          $table->integer('admin_mode_id')->unsigned();
          $table->foreign('admin_mode_id')
                ->references('id')->on('tbl_adminmode')
                ->onDelete('cascade');
          
          });
          
          1. ActivePrinciple和medecine pivot
          2. Schema::create('medecine_active_princip', function(Blueprint $table) {
            
            $table->increments('id');
            
            $table->integer('medecine_id')->unsigned();
            $table->foreign('medecine_id')
                  ->references('id')->on('tbl_medecine')
                  ->onDelete('cascade');
            
            $table->integer('active_princip_id')->unsigned();
            $table->foreign('active_princip_id')
                  ->references('id')->on('tbl_activeprincip')
                  ->onDelete('cascade');
            
            });
            

            该视图生成的数据结果没有任何错误,但仍然几乎可以加载几分钟。我失踪了什么?

            Thnx并抱歉这篇长篇文章

            模型

            MEDECINE

            class Medecine extends Model
            {
                protected $table='tbl_medecine';
            
            
                    public function pharmacologics() 
                {
            
                    return $this->belongsToMany('App\Pharmacologic');
            
                }
            
                        public function therapeutics() 
                {
            
                    return $this->belongsToMany('App\Therapeutic');
            
                }
            
                            public function galenics() 
                {
            
                    return $this->belongsToMany('App\Galenic');
            
                }
            
                            public function administrationmodes() 
                {
            
                    return $this->belongsToMany('App\AdministrationMode');
            
                }
            
                            public function activeprinciples() 
                {
            
                    return $this->belongsToMany('App\ActivePrinciple');
            
                }
            }
            

            药理学

            class Pharmacologic extends Model
            {
                //
                protected $table='tbl_pharmacologic';
            
                public function medecines() 
                {
            
                    return $this->belongsToMany('App\Medecine');
            
                }
            }
            

            等等......

0 个答案:

没有答案