小编rfp*_*pdl的帖子

laravel eloquent渴望加载嵌套条件

我有2个表正在使用预先加载,然后在那个急切的加载中使用嵌套条件:

//migration for lead table
public function up()
{
    Schema::create('leads', function(Blueprint $table)
    {
        $table->engine = 'InnoDB';
        $table->increments('id');
        $table->string('first_name',255);
        $table->string('surname',255);
    });

    Schema::table('leads', function($table)
    {
        $table->foreign('create_by')->references('id')->on('employees')->onDelete('cascade');
    });
}

//lead for lead detail emails
public function up()
{
    Schema::create('lead_detail_emails', function(Blueprint $table)
    {
        $table->engine = 'InnoDB';
        $table->increments('id');
        $table->integer('lead_id')->unsigned();
        $table->string('email',255);
    });

    Schema::table('lead_detail_emails',function($table)
    {
        $table->foreign('lead_id')->references('id')->on('leads')->onDelete('cascade');
    });
}

//leads model
class LeadsModel extends Eloquent
{
    protected $table = 'leads';

    public function emails()
    {
        return $this->hasMany('LeadDetailEmailsModel','lead_id','id');
    }
}

//lead detail emails
class LeadDetailEmail extends Eloquent
{
    protected $table …
Run Code Online (Sandbox Code Playgroud)

php eager-loading laravel

4
推荐指数
1
解决办法
5199
查看次数

EXEC %%System().FireTrigger

我只是想知道这是什么?

EXEC %%System().FireTrigger(ID = 225, ID = 102, ID = 0, ID = 0, Value = @server,
ID = -1, ID = 0, ID = 0, Value = NULL, 
ID = 7, Value = @server, Value = @srvproduct2, Value = @provider, Value = @datasrc, Value = @location, Value = NULL, Value = @catalog)
Run Code Online (Sandbox Code Playgroud)

我一直试图在 mssql 中寻找它,但我找不到它,这是什么意思?我知道EXEC是用来执行存储过程的,但是什么是%%System()?

什么是FireTrigger?它是系统中的嵌入式命令吗?外部dll?一直在尝试谷歌,但目前似乎含糊不清。

sql-server

3
推荐指数
1
解决办法
1030
查看次数

Laravel 迁移两表外键依赖

我有两张桌子(员工和地区),

员工和地区

我正在尝试使用迁移来创建它,不幸的是它不会让我,我得到:

[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table regions` add constraint regions_create_by_foreign foreign key (`create_by`) references `employees` (`id`))

[PDOException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
Run Code Online (Sandbox Code Playgroud)

以下是我的迁移代码:

FILE: 2014_10_11_052414_create_regions_table.php  //this is the migration file for regions

    Schema::create('regions', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('name',50)->unique();
        $table->integer('head_office_flag');
        $table->integer('create_by')->unsigned();
        $table->foreign('create_by')->references('id')->on('employees'); //this is the problem
        $table->datetime('create_datetime')->default(DB::raw('CURRENT_TIMESTAMP'));
    });

FILE: 2014_10_12_110447_create_employees_table.php //this is the migration file for employees

    Schema::create('employees', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('first_name',50);
        $table->string('surname',50);
        $table->string('email',100);
        $table->integer('region_id');   
        $table->string('photos',255)->nullable();
        $table->string('mobile_no',50); …
Run Code Online (Sandbox Code Playgroud)

php laravel artisan-migrate

3
推荐指数
1
解决办法
3923
查看次数