Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
0
feb. 25
938
2
sep. 23
9878
2
jul. 22
2719
0
mei 21
9038
2
jun. 17
4356