We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

How to read additional fields by hasManyToMany()?

Assuming data table co_invoices_x_products has an addtional field ordernum, How to read the field out by hasManyToMany()?



8.4k

by using hasManyToMany it cant be since Has-Many-to-Many will return model instances of the referenced model ( which is either co_invoices or co_products ) using inner join

you have to make your own query to get your ordernum

Yeah - you can't read it if you only have a many-to-many relationship. However, there's nothing saying you can't also make a hasMany relationship between co_invoices and co_invoices_x_products



31.1k
edited Dec '20

Thanks for giving the idea. I'll try that out later. And now I'm trying to code a custom many-to-many query builder: https://forum.phalcon.io/discussion/21033/question-about-query-builder :D

Yeah - you can't read it if you only have a many-to-many relationship. However, there's nothing saying you can't also make a hasMany relationship between co_invoices and co_invoices_x_products