Pular para o conteúdo
Odoo Menu
  • Entrar
  • Experimente grátis
  • Aplicativos
    Finanças
    • Financeiro
    • Faturamento
    • Despesas
    • Planilhas (BI)
    • Documentos
    • Assinar Documentos
    Vendas
    • CRM
    • Vendas
    • PDV Loja
    • PDV Restaurantes
    • Assinaturas
    • Locação
    Websites
    • Criador de Sites
    • e-Commerce
    • Blog
    • Fórum
    • Chat ao Vivo
    • e-Learning
    Cadeia de mantimentos
    • Inventário
    • Fabricação
    • PLM - Ciclo de Vida do Produto
    • Compras
    • Manutenção
    • Qualidade
    Recursos Humanos
    • Funcionários
    • Recrutamento
    • Folgas
    • Avaliações
    • Indicações
    • Frota
    Marketing
    • Redes Sociais
    • Marketing por E-mail
    • Marketing por SMS
    • Eventos
    • Automação de Marketing
    • Pesquisas
    Serviços
    • Projeto
    • Planilhas de Horas
    • Serviço de Campo
    • Central de Ajuda
    • Planejamento
    • Compromissos
    Produtividade
    • Mensagens
    • Aprovações
    • Internet das Coisas
    • VoIP
    • Conhecimento
    • WhatsApp
    Aplicativos de terceiros Odoo Studio Plataforma Odoo Cloud
  • Setores
    Varejo
    • Loja de livros
    • Loja de roupas
    • Loja de móveis
    • Mercearia
    • Loja de ferramentas
    • Loja de brinquedos
    Comida e hospitalidade
    • Bar e Pub
    • Restaurante
    • Fast Food
    • Hospedagem
    • Distribuidor de bebidas
    • Hotel
    Imóveis
    • Imobiliária
    • Escritório de arquitetura
    • Construção
    • Administração de propriedades
    • Jardinagem
    • Associação de proprietários de imóveis
    Consultoria
    • Escritório de Contabilidade
    • Parceiro Odoo
    • Agência de marketing
    • Escritório de advocacia
    • Aquisição de talentos
    • Auditoria e Certificação
    Fabricação
    • Têxtil
    • Metal
    • Móveis
    • Alimentação
    • Cervejaria
    • Presentes corporativos
    Saúde e Boa forma
    • Clube esportivo
    • Loja de óculos
    • Academia
    • Profissionais de bem-estar
    • Farmácia
    • Salão de cabeleireiro
    Comércio
    • Handyman
    • Hardware e Suporte de TI
    • Sistemas de energia solar
    • Sapataria
    • Serviços de limpeza
    • Serviços de climatização
    Outros
    • Organização sem fins lucrativos
    • Agência Ambiental
    • Aluguel de outdoors
    • Fotografia
    • Aluguel de bicicletas
    • Revendedor de software
    Navegar por todos os setores
  • Comunidade
    Aprenda
    • Tutoriais
    • Documentação
    • Certificações
    • Treinamento
    • Blog
    • Podcast
    Empodere a Educação
    • Programa de educação
    • Scale Up! Jogo de Negócios
    • Visite a Odoo
    Obtenha o Software
    • Baixar
    • Comparar edições
    • Releases
    Colaborar
    • Github
    • Fórum
    • Eventos
    • Traduções
    • Torne-se um parceiro
    • Serviços para parceiros
    • Cadastre seu escritório contábil
    Obtenha os serviços
    • Encontre um parceiro
    • Encontre um Contador
    • Conheça um consultor
    • Serviços de Implementação
    • Referências de Clientes
    • Suporte
    • Upgrades
    Github YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Faça uma demonstração
  • Preços
  • Ajuda

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

  • CRM
  • e-Commerce
  • Financeiro
  • Inventário
  • PoS
  • Projeto
  • MRP
All apps
É necessário estar registrado para interagir com a comunidade.
Todas as publicações Pessoas Emblemas
Marcadores (Ver tudo)
odoo accounting v14 pos v15
Sobre este fórum
É necessário estar registrado para interagir com a comunidade.
Todas as publicações Pessoas Emblemas
Marcadores (Ver tudo)
odoo accounting v14 pos v15
Sobre este fórum
Ajuda

How does Odoo store One2Many fields?

Inscrever

Seja notificado quando houver atividade nesta publicação

Esta pergunta foi sinalizada
fieldsdatabasestoreone2many
4 Respostas
22297 Visualizações
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
Cancelar
Avatar
Temur
Melhor resposta

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
Cancelar
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
Melhor resposta

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
Cancelar
Está gostando da discussão? Não fique apenas lendo, participe!

Crie uma conta hoje mesmo para aproveitar os recursos exclusivos e interagir com nossa incrível comunidade!

Inscreva-se
Publicações relacionadas Respostas Visualizações Atividade
How to store 2 fields in stock.quant database?
fields database store odoo9
Avatar
0
nov. 16
4418
Can I store field function with the type one2many? Resolvido
function fields store one2many
Avatar
Avatar
Avatar
Avatar
4
jan. 24
14894
delete fields from database without uninstall? Resolvido
fields database
Avatar
Avatar
Avatar
Avatar
4
dez. 24
32195
One2many field odoo 14
fields one2many
Avatar
0
jul. 22
4321
How to store my field.function?
function fields database store odoo9
Avatar
Avatar
1
dez. 16
5918
Comunidade
  • Tutoriais
  • Documentação
  • Fórum
Open Source
  • Baixar
  • Github
  • Runbot
  • Traduções
Serviços
  • Odoo.sh Hosting
  • Suporte
  • Upgrade
  • Desenvolvimentos personalizados
  • Educação
  • Encontre um Contador
  • Encontre um parceiro
  • Torne-se um parceiro
Sobre nós
  • Nossa empresa
  • Ativos da marca
  • Contato
  • Empregos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidade
  • Segurança
الْعَرَبيّة 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 é um conjunto de aplicativos de negócios em código aberto que cobre todas as necessidades de sua empresa: CRM, comércio eletrônico, contabilidade, estoque, ponto de venda, gerenciamento de projetos, etc.

A proposta de valor exclusiva Odoo é ser, ao mesmo tempo, muito fácil de usar e totalmente integrado.

Site feito com

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