A hasMany relation is generated with a snake_cased column derived from the parent's schema name, but the column the migration actually creates comes from the child's property name. For multi-word schema names the two never match.
ProductVariant.yaml:
properties:
id: {type: integer, format: int64}
packagings:
type: array
items:
$ref: '#/components/schemas/ProductPackaging'
ProductPackaging.yaml:
properties:
id: {type: integer, format: int64}
productVariant:
$ref: '#/components/schemas/ProductVariant'
The migration creates productVariant_id, and the belongs-to side is generated correctly:
// base/ProductPackaging.php
return $this->hasOne(ProductVariant::class, ['id' => 'productVariant_id']);
The has-many side is not:
// base/ProductVariant.php
return $this->hasMany(ProductPackaging::class, ['product_variant_id' => 'id']);
Using it throws:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'product_variant_id' in 'WHERE'
SELECT * FROM `product_packaging` WHERE `product_variant_id`=1
A hasMany relation is generated with a snake_cased column derived from the parent's schema name, but the column the migration actually creates comes from the child's property name. For multi-word schema names the two never match.
ProductVariant.yaml:
ProductPackaging.yaml:
The migration creates productVariant_id, and the belongs-to side is generated correctly:
// base/ProductPackaging.php
return $this->hasOne(ProductVariant::class, ['id' => 'productVariant_id']);The has-many side is not:
// base/ProductVariant.php
return $this->hasMany(ProductPackaging::class, ['product_variant_id' => 'id']);Using it throws: