开发者

Update the ID of a model in symfony

I am currently using the symfony admin-generator a manipulate a database. The database is already created and in use and one of the things it does differently than what a normally setup symfony database does is use a varchar as a primary key rather than symfony's method of using ints for all primary keys.

The problem I am having is being able to edit and update this primary key in a form. The issue is that, when I try to edit the key, the form throws an error and says "Invalid". The error, I can assume, comes from the fact that th开发者_如何学Goe new PK does not match the old one. I suppose I have these options:

  1. Delete the old model, create a new one and save it.

  2. Do not allow them to edit the ID. They will have to delete the model instead and recreate it.

  3. Do not allow them to make or edit the ID and instead infer it from an attribute.

  4. Change the database architecture so that the model has an auto-increment integer PK. Then use a unique varchar index for the previous PK.

Now that I think about it, number 3 would be ideal because the model as a "Name" field, which could easily have an ID inferred from it. However, this would still cause the issue in 1 when they update the name.

I do not like option 2 at all, and I think I would actually prefer number 4. I assume 4 is the easiest way and it could be done, but I would like to at least know if number 1 could be implemented for future reference.


Based on your comment response I would refactor the database. I'd create an auto_increment integer PK and create a unique index on the slug column.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜