Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
7015 Lượt xem

I've seen a model that has a status or state field which is done as fields.selection() and I've seen it done as a fields.many2one().  Both ways of doing it seem to work fine and do the job. 

I suppose many2one is best when you expect to have new values to add over time. 

I am wondering if there are any best practices as to which should be used under what cirmustances.  And what are the advantages and disavantages of each.  Or any notable experince in using one or the other.

 

Ảnh đại diện
Huỷ bỏ

Hello Best practice according to me is to use : many2one : for relations with another object (wich can be edited... add choice, ...) Eg: Category, manager, ... Selection : A static list (not evolutive). Eg: Status (Open / WIP / Close) JKE

Tác giả

Thank you jke, that is simple and makes sense.

Câu trả lời hay nhất

I wouldn't say that this is best practices, but here are some "differences" that would be your consideration points when making the design decision:

  • selection is a fixed list once rendered (this also applies to many2one fields which is viewed with widget="selection"), you cannot apply domain to it
  • selection will be pulled altogether at once when HTML is rendered (this also applies to many2one fields which is viewed with widget="selection").  Not a good choice if you have hundreds or thousands selection.
  • selection fields (this does NOT apply to many2one fields viewed with widget="selection") is not stored as a Foreign Key.  So you can remove an entry from the selection and no integrity problem will ensue.

As for the states, you can still make it a selection field whilst making it dynamic by supplying the entries from a table.  Selection field can accept a function as selection source.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 9 19
3469
4
thg 10 21
37637
1
thg 10 20
12557
1
thg 3 15
5041
1
thg 8 25
3808