doupo5861 2014-10-13 04:18
浏览 63
已采纳

带有附加参数的laravel pivot表

I'm building a laravel app that tracks projects. A user can define tasks and attach them to projects.

I'd like the user to be able to have a list of tasks that can be re-used for multiple projects. This is simple enough using a pivot table that links projects and tasks:

public function up()
{
    Schema::create('project_task', function($table)
    {
        $table->increments('id');
        $table->integer('project_id');
        $table->integer('task_id');
        $table->timestamps();
    });
}

However, I'd like the user to be able to set different due dates for tasks depending on the project. So on project 1, Task A is due in one week. On project 2, Task A is due in a month.

What's the best table schema to store these type of values? Does there need to be another pivot table that links the task parameters to the project ID? I'm not sure how to handle this.

Thanks for your input.

EDIT: I'm using the Eloquent ORM, so the pivot rows are never really exposed, it just grabs the Task object associated with the Project.

  • 写回答

1条回答 默认 最新

  • duanliang4009 2014-10-13 04:29
    关注

    You can simply add due_date field to the project_task table. So in total you will have three tables project, task and project_task (which you have in your question)

    Like this you will define the task once and can assign different due date for each project

    Edit

    You can define a custom pivot model that includes the due_date see Defining A Custom Pivot Model

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line