Skip to Content
Menu
This question has been flagged

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?

 

Avatar
Discard
Related Posts Replies Views Activity
0
Feb 25
1076
2
Sep 23
10207
2
Jul 22
2853
0
May 21
9184
2
Jun 17
4494