Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Why Odoo use Create Unique Index in some model in base module?

By
sepdau
on 6/24/14, 1:13 PM 1,415 views

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?

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/24/14, 1:13 PM
Seen: 1415 times
Last updated: 3/16/15, 8:10 AM