dongre6073 2013-02-03 22:30
浏览 26
已采纳

Koahan ORM:为多对多关系添加额外数据

I have my models setup as a many-to-many using through with a pivot table. However, I would like to add some extra data into the pivot table.

In the past (kohana 3.0) I was able to provide extra data with the add method

$obj->add('alias', $related, array('extra'=>'data'))

But its seems in Kohana 3.3 that the add method does not provide the third parameter for extra data, and I cannot seem to find how to do this short of after saving, adding more data then re-saving.

  • 写回答

1条回答 默认 最新

  • drryyiuib43562604 2013-02-06 11:23
    关注

    This isn't supported anymore since Kohana 3.1.

    The reason they removed it (Source: http://dev.kohanaframework.org/issues/3754):

    We decided to remove this because it's better to use a through model if you need to put data in your pivot table. Inserting the data directly in the add() method bypasses validation and filtering that would normally be in your model. Use a model if you need data in your through table. We won't be changing this.

    You now have to make a model for the pivot table and place the additional information in that model.

    Then instead of using has_many "through" (n:n) you should use has_many (1:n) relationship for both tables to the pivot table.

    I hope this answers your question.

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

报告相同问题?