[PonyORM-list] Inquire about Foreign Key

Agatha Ng agathang93 at gmail.com
Wed Oct 10 19:26:23 UTC 2018


Hello,

I ran into some problem when building the entity relationship with Pony
ORM. Following are two tables in the database.

TABLE `branches` (
>   `id` int(11) NOT NULL,
>   `client` varchar(64) NOT NULL,
>   `pid` int(11) DEFAULT NULL,
>   PRIMARY KEY (`id`,`client`),
>   KEY `branches_ibfk_1` (`pid`),
>   CONSTRAINT `branches_ibfk_1` FOREIGN KEY (`pid`) REFERENCES `branches`
> (`id`)
> )
> TABLE `branches_config` (
>   `id` int(11) NOT NULL AUTO_INCREMENT,
>   `bid` int(11) NOT NULL,
>   `client` varchar(64) NOT NULL,
>   PRIMARY KEY (`id`),
>   KEY `branches_config_ibfk_1` (`bid`,`client`),
>   CONSTRAINT `branches_config_ibfk_1` FOREIGN KEY (`bid`, `client`)
> REFERENCES `branches` (`id`, `client`)
> )


For the 'branches' table, 'id' is a part of the primary key and also
referred by 'pid'. I tried to define 'id' as a Set attribute to satisfy the
one-to-many self-reference. But Set attribute cannot be a part of primary
key. Could you tell me how to define such a relationship?

For the 'branches_config' table, (bid, client) refers 'branches' (id,
client). How to define the reference between two composite key?

Thank you and I look forward to hearing from you.

Best wishes,
Agatha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20181010/2acf15cf/attachment.html>


More information about the ponyorm-list mailing list