Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Food & Hospitality
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Guest House
    • Distributor nápojů
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Trades
    • Údržbář
    • IT hardware a podpora
    • Solar Energy Systems
    • Výrobce obuvi
    • Úklidové služby
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

How does Odoo store One2Many fields?

Odebírat

Get notified when there's activity on this post

This question has been flagged
fieldsdatabasestoreone2many
4 Odpovědi
22296 Zobrazení
Avatar
Muszik Adrián

i need to access One2Many field via SQL query, but i can't find it in the  Model's table. my model is called `subscription.subscription`

 and it has this field:

'function_line_ids': fields.one2many('subscription.function.subscription.line', 'subscription_id', 'Functions'),


i need this field, but as i said cant find it on the model's table. Where does odoo store this information?

1
Avatar
Zrušit
Avatar
Temur
Nejlepší odpověď

For remember easily, you can assume that in database "ID's are saved at «many» side" i.e. if you've two objects(models) 'object_a' and 'object_b' and you've relational field in the 'object_a' :

  • if field type is one2many, then ID's(of object_a) are saved in 'object_b' (object_b is at «many» side, it contains ids)

  • if field type is 'many2one', then ID's(of object_b) are saved in 'object_a' (object_a is at «many» side, it contains ids)

  • if field type is many2many, then ID's(of both objects) are saved in the separated table (it's exception as ids are not either in A or in B, but they are in the table that may be named using "relation" parameter of many2many field)

5
Avatar
Zrušit
Temur

So in your case, ID's of subscription_subscription records are saved in the subscription_function_subscription_line table.

Temur

take look of table of subscription.function.subscription.line in your database, you should find there corresponding foreign keys (id's of subscription.subscription). that's how one2many field is stored in the database.

Andika Priyotama

This is interesting.

I've spent days trying to figure out this kind of similar problem without success.

I executed a query to insert into a table which is the «many» side, including the value of the foreign key ID from the «one» side. I thought if I access the One2many field (in the «one» side), it would return the objects from the model where it was related to. Apparently it doesn't work like this: say, after I execute INSERT query successfully (and the data are successfully stored on the «many» side table), I accessed it using something like `self.report_move_lines`, but it returned empty.

Well, is there something that I'm missing here?

If this discussion is still active, I'd be thankful for the help.

Avatar
Eric
Nejlepší odpověď

One2many fields aren't actually stored on the database table though. So you won't be able to query results using that field with sql.  If you want to find your subscription lines per subscription, you could actually use the search function to return a list of ids, then browse, or read using the list of ids that are returned from the search function.  Example:


class subscription_subscription(orm.Model):

     def get_subscription_lines(self, cr, uid, sub_id, context=None):

         subscription_line_obj = self.pool.get('subscription.function.subscription.line')

         # get subscription lines based on the current subscription i

         subscription_line_ids = subscription_line_obj.search(cr, uid, [('subscription_id','=',sub_id )], context)

       

         # now subscription_line_ids should have a list of ids like this = [1,2,3]

         # you can browse or read using the subscription_line_ids for the data

        subscription_line_recs = subscription_line_obj.browse(cr, uid, subscription_line_ids, context)

        subscription_line_vals = subscription_line_obj.read(cr, uid, subscription_line_ids, ['names','of','fields'], context)


        # subscription_line_recs is a list of objects where the data can be used by using dot notation on the object

        # subscription_line_vals is a list of dictionaries that contains the names of the fields specified in the read function


       return subscription_line_recs or subscription_line_vals


If you still need to use sql to query subscription lines then  you can use the database cursor to do this, but it is not recommended

cr.execute(""" SELECT * FROM subscription_function_subscription_line WHERE subscription_id = 1 """)

result_recs = cr.fetchall()


         


2
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
How to store 2 fields in stock.quant database?
fields database store odoo9
Avatar
0
lis 16
4418
Can I store field function with the type one2many? Vyřešeno
function fields store one2many
Avatar
Avatar
Avatar
Avatar
4
led 24
14894
delete fields from database without uninstall? Vyřešeno
fields database
Avatar
Avatar
Avatar
Avatar
4
pro 24
32195
One2many field odoo 14
fields one2many
Avatar
0
čvc 22
4321
How to store my field.function?
function fields database store odoo9
Avatar
Avatar
1
pro 16
5918
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now