[odb-users] Defining one-to-many bidirectional relationship
david bowe
dpbowe at hotmail.com
Fri Feb 10 10:07:18 EST 2017
Thanks Micheal,
I am creating a simple database schema so I will remove the inverse pointer. I think I misunderstood what is required for the relationship to be bidirectional (sorry still pretty new to this).
When I compile the code now it creates the correct schema (below), however, the supplier foreign key in the orders table does not show a reference to the suppliers table. Any ideas why this might be? The use of boost pointers maybe?? Sorry to keep asking
David
CREATE TABLE "suppliers" (
"id" BIGSERIAL NOT NULL PRIMARY KEY,
"title" VARCHAR(255) NOT NULL,
"phone" VARCHAR(255) NULL,
"address_line_1" VARCHAR(255) NOT NULL,
"address_line_2" VARCHAR(255) NULL,
"address_line_3" VARCHAR(255) NULL,
"address_line_4" VARCHAR(255) NULL,
"address_line_5" VARCHAR(255) NULL,
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP);
CREATE TABLE "orders" (
"id" BIGSERIAL NOT NULL PRIMARY KEY,
"code" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"supplier_id" BIGINT NOT NULL);
________________________________
From: Michael <mwpowellhtx at gmail.com>
Sent: 10 February 2017 14:48
To: david bowe
Subject: Re: [odb-users] Defining one-to-many bidirectional relationship
On February 10, 2017 3:45:59 AM EST, david bowe <dpbowe at hotmail.com> wrote:
>Thanks for the reply Micheal,
>
>
>Although, I'm not quite sure I understand. Do you mean that I should
>only use a reference pointer on one side of the database map? I want to
>be able to query up and down through the relationship as necessary.
I am not as familiar with the odb side of things as I am ORM, per se. AFAIK, *-* would support that, yes, with specific restrictions being domain concerns.
All I can encourage is just to think it through. Perhaps develop a couple of domain-only test cases to exercise the hypotheses.
HTH
>David
>
>________________________________
>From: Michael <mwpowellhtx at gmail.com>
>Sent: 09 February 2017 17:29
>To: david bowe
>Subject: Re: [odb-users] Defining one-to-many bidirectional
>relationship
>
>
>
>On February 9, 2017 5:53:45 AM EST, david bowe <dpbowe at hotmail.com>
>wrote:
>>Hi there,
>>
>>
>>I have been trying to define a one to many relationship with the
>>attached code. However, when defining the relationship pointers I get
>>the below error asking me to define a database type. I can do this and
>>the code will compile but it creates a relationship through a
>>supplier_order table which is not what I need. I need each order to
>>reference one suppler
>
>That's not typically how best to normalize this kind of object to
>database mapping. Doesn't matter if we're talking about odb/C++ or
>NHibernate/C#. What you described is more of a domain layer and/or
>business logic concern IMPO.
>
>In this case the * on the order to supply side is 1, but the mapping
>can be the same.
>
>HTH
>
>>database.hxx:111:46: error: unable to map C++ type
>>'::__gnu_cxx::new_allocator< ::boost::weak_ptr< ::order >
>>::this_type'
>>used in data member 'orders_' to a PostgreSQL database type
>>
>>database.hxx:111:46: info: use '#pragma db value_type' to specify the
>>database type
>>
>>
>>Could anybody help me with what I am doing wrong?
>>
>>
>>Thanks,
>>
>>
>>David
>
>--
>Sent from my Android device with K-9 Mail. Please excuse my brevity.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
More information about the odb-users
mailing list