Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

How does Odoo store One2Many fields?

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
fieldsdatabasestoreone2many
4 Respuestas
22293 Vistas
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
Descartar
Avatar
Temur
Mejor respuesta

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
Descartar
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
Mejor respuesta

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
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
How to store 2 fields in stock.quant database?
fields database store odoo9
Avatar
0
nov 16
4417
Can I store field function with the type one2many? Resuelto
function fields store one2many
Avatar
Avatar
Avatar
Avatar
4
ene 24
14894
delete fields from database without uninstall? Resuelto
fields database
Avatar
Avatar
Avatar
Avatar
4
dic 24
32194
One2many field odoo 14
fields one2many
Avatar
0
jul 22
4320
How to store my field.function?
function fields database store odoo9
Avatar
Avatar
1
dic 16
5915
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

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