Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 通过联接表对多态HasMany/HasOne进行续集_Postgresql_Sqlite_Sequelize.js - Fatal编程技术网

Postgresql 通过联接表对多态HasMany/HasOne进行续集

Postgresql 通过联接表对多态HasMany/HasOne进行续集,postgresql,sqlite,sequelize.js,Postgresql,Sqlite,Sequelize.js,我有一个客户表、一个地址表和一个名为CustomerAddress的联接表。 客户需要发货地址、账单地址、默认地址,并且客户的所有地址都需要在字段addresses中可访问,这是因为地址表是多态的 我希望在客户表或地址表中没有目标键或外部/目标键的情况下执行此操作,并依靠CustomerAddress表指定哪个地址是哪个地址,这是连接表的内容: //CustomerAddress schema = { address_id: { type: Sequelize

我有一个客户表、一个地址表和一个名为CustomerAddress的联接表。 客户需要发货地址、账单地址、默认地址,并且客户的所有地址都需要在字段
addresses
中可访问,这是因为地址表是多态的

我希望在客户表或地址表中没有目标键或外部/目标键的情况下执行此操作,并依靠CustomerAddress表指定哪个地址是哪个地址,这是连接表的内容:

//CustomerAddress
    schema = {
      address_id: {
        type: Sequelize.INTEGER,
        unique: 'customeraddress_address'
      },
      // Type of address eg. shipping, default, billing
      address: {
        type: Sequelize.STRING,
        unique: 'customeraddress_address'
      },
      customer_id: {
        type: Sequelize.INTEGER,
        unique: 'customeraddress_address',
        references: null
      }
    }

我不知道如何建立协会来实现这一点。非常感谢您提供的任何帮助。

实现这一点的方法实际上是通过一个归属者协会,在这里您暗示这是一个归属者协会。通过这种方式,它使用联接表作为默认值。区别在于它返回一个数组而不是一个对象,这会破坏点。一种折衷方法可能是,在将instanceMethod重写为JSON时,将数组变形为一个对象,或者创建一个自定义setter/getter,在获取关联时执行此操作