콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

I see in base module some model write this

def _auto_init(self, cr, context=None):

        super(ir_actions_act_window_view, self)._auto_init(cr, context)

        cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = \'act_window_view_unique_mode_per_action\'')

        if not cr.fetchone():

            cr.execute('CREATE UNIQUE INDEX act_window_view_unique_mode_per_action ON ir_act_window_view (act_window_id, view_mode)')

 

I wanna know why odoo create unique index for this model?

what is situation we can use it? Is that situable for model has 10 records, 100k records, 500k records and model have data increase dailly about 1k - 5k records per day.

My code to  check unique column of table but irgore case sensitive. Is that the right way to do that? Do we will apply this for all model have this contraints? 

 

_sql_constraints = [
        ('name_unique', 'unique(name)', 'Name must be unique!'),
        ('code_unique', 'unique(code)', 'Code must be unique!'),
    ]

    def _auto_init(self, cr, context=None):
        super(vhr_head_office, self)._auto_init(cr, context)
        # Use unique index to implement unique constraint on the lowercase name (not possible using a constraint)
        cr.execute("SELECT indexname FROM pg_indexes WHERE indexname = 'vhr_head_office_name_unique_index'")
        if not cr.fetchone():
            cr.execute("""CREATE UNIQUE INDEX "vhr_head_office_name_unique_index" ON vhr_head_office
                            (lower(name))""")

 

Finally what is problem when we indexing a lot of model?

 

아바타
취소
관련 게시물 답글 화면 활동
0
2월 25
1103
2
9월 23
10340
2
7월 22
2908
0
5월 21
9225
2
6월 17
4529