[odb-users] std::map<Entity, int>

Adnan RIHAN axel50397 at gmail.com
Tue Nov 25 18:25:35 EST 2014


Hi Boris

On 24 novembre 2014 at 11:16:00, Boris Kolpackov (boris at codesynthesis.com(mailto:boris at codesynthesis.com)) wrote:

> #pragma db value
> struct ProductKey
> {
> QSharedPointer p;
> };

I tried this, the file was correctly compiled by ODB, but I needed to make some changes. As I needed many methods in the struct, I’ve decided to create a class, my class structure is like this:

- An Invoice has a Set of QSharedPointer<Cart>.
- A Cart has 1 struct CartId, 1 quantity (int).
- A struct CartId is 1 QWeakPointer<Invoice>, 1 QSharedPointer<Offer>.
- An Offer has 1 QSharedPointer<Product>, 1 price (int).
- A Product has many properties.

I want to make a composite key for struct CartId, and I think I’ve followed the doc, but I now have an odb compilation issue:
> apps/LGC/src/Models/Invoice/Invoice.hpp:107:0: warning: ignoring #pragma dbb member [-Wunknown-pragmas]
>  #   pragma  dbb  member(Invoice::m_cart)         not_null
>  ^
> apps/LGC/src/Models/Invoice/../Cart/Cart.hpp:81:45: error: name 'CartId' in db pragma column does not refer to a data member
> apps/LGC/src/Models/Invoice/../Cart/Cart.hpp:82:40: error: unable to resolve type name 'CartId::m_invoice' in db pragma value
> apps/LGC/src/Models/Invoice/../Cart/Cart.hpp:83:38: error: unable to resolve type name 'CartId::m_offer' in db pragma value

Here is my Cart.hpp (odb section, at the end of the file):
> # ifdef     ODB_COMPILER
> #   pragma  db  value(CartId)               column("")
> #   pragma  db  value(CartId::m_invoice)    column("invoice_id")
> #   pragma  db  value(CartId::m_offer)      column("offer_id")
> 
> #   pragma  db  model                       version(1, 1, open)
> #   pragma  db  object(Cart)                table("invoice_carts")
> #   pragma  db  member(Cart::m_data)        id  auto
> #   pragma  db  member(Cart::m_quantity)    not_null    default(1)
> #   pragma  db  member(Cart::isDirty)       transient
> # endif

And for reference, my Invoice.hpp (because it also failed, but not anymore):
> # ifdef     ODB_COMPILER
> #   pragma  db  model                           version(1, 1, open)
> #   pragma  db  object(Invoice)                 table("invoices")
> #   pragma  db  member(Invoice::m_id)           id  auto
> #   pragma  db  member(Invoice::m_cart)         not_null    // QSet<QSharedPointer<Cart> >
> #   pragma  db  member(Invoice::m_customer)     not_null    column("customer_id")   default(1)
> #   pragma  db  member(Invoice::m_discount)     not_null    default(0)
> #   pragma  db  member(Invoice::m_comment)      null
> #   pragma  db  member(Invoice::m_barcode)      not_null
> #   pragma  db  member(Invoice::m_createdAt)    not_null    column("created_at")
> #   pragma  db  member(Invoice::m_updatedAt)    null        column("updated_at")
> #   pragma  db  member(Invoice::m_deletedAt)    null        column("deleted_at")
> #   pragma  db  member(Invoice::isDirty)        transient
> # endif

In your previous email, you wrote: "Interestingly, wrapping the pointer into a composite value seems to work”, could the error come from the fact that I’m making a composite of 2 unsupported data (objects).

Do I need to wrap the pointer into 2 distinct composite values, then in my struct CartId I would have 2 other structs?
--  
Cordialement, Adnan RIHAN.
Directeur-Gérant de Eolis-Software, société de services informatiques.  

GPG: 5675-62BA (https://keybase.io/max13/key.asc)
-> Si vous n'utilisez pas GPG mais souhaitez quand même m’envoyer un e-mail chiffré: (https://encrypt.to/0x567562BA).



More information about the odb-users mailing list