I don't pass extra fields to many to many relations.
May schema is :
create table attributes
(
id int auto_increment
primary key,
name varchar(255) not null,
status enum('active', 'deleted', 'unactive') default 'active' not null,
creared_at datetime not null,
updated_at datetime null
)
;
create table products
(
id int auto_increment
primary key,
title varchar(255) null,
summary varchar(255) null,
content text not null,
meta_title varchar(255) null,
meta_key varchar(255) null,
meta_descrp varchar(255) null,
status enum('active', 'deleted', 'unactive', '') default '' not null,
created_at datetime not null,
updated_at datetime null,
deleted_at datetime null
)
;
create index status_idx
on products (status)
;
create table products_attributes
(
product_id int not null,
attribute_id int not null,
attributes_values text not null,
constraint products_attributes_ibfk_1
foreign key (product_id) references mobile.products (id)
on delete cascade,
constraint products_attributes_ibfk_2
foreign key (attribute_id) references mobile.attributes (id)
on update cascade on delete cascade
)
;
create index attribute_id
on products_attributes (attribute_id)
;
create index product_id
on products_attributes (product_id)
;
create table users
(
id int auto_increment
primary key,
username int not null,
user_role set('admin') default 'admin' not null,
password varchar(255) not null,
status enum('acitive', 'unactive', 'deleted', '') default 'acitive' not null,
created_at datetime not null,
updated_at datetime null,
deleted_at datetime null,
constraint username
unique (username)
);
My relations :
$this->hasManyToMany(
"id",
"\ProductsAttributes",
"product_id",
"attribute_id",
"\Attributes",
'id',
['alias'=>'attributes','params'=>['columns'=>' Products.*, Attributes.*, ProductsAttributes.*']]
);
But generated error :
Phalcon \ Mvc \ Model \ Exception
Unknown model or alias 'Products' (11), when preparing: SELECT Products.id, Attributes.value FROM [\Attributes] INNER JOIN [\ProductsAttributes] ON [\ProductsAttributes].[attribute_id] = [\Attributes].[id] WHERE [\ProductsAttributes].[product_id] = :APR0