We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon 4, problem with relations

I have some raltions in model

$this->hasManyToMany("id", "ProductMedia", "product_id", "media_id", "Media", "id", [ "alias" => 'media' ]);

$this->hasManyToMany("id", "ProductEvents", "product_id", "event_id", "Event", "id", [ "alias" => "events" ]);

When I try to get $product->media - its ok, but when I get $product->events I got an error

Scanning error before '].id DESC LIMIT ...' when parsing: SELECT [Event].* FROM [Event] INNER JOIN [ProductEvents] ON [ProductEvents].[event_id] = [Event].[id] WHERE [ProductEvents].[product_id] = :APR0: ORDER BY [].id DESC LIMIT :APL0:

Where could the problem be?

Check the table definitions. It appears that ProductEvents isn't set up the same way as ProductMedia



300
edited Sep '20

Scanning error before '].id DESC LIMIT ...' when parsing: SELECT [Image].* FROM [Image] INNER JOIN [ProductImages] ON [ProductImages].[image_id] = [Image].[id] WHERE [ProductImages].[product_id] = :APR0: ORDER BY [].id DESC LIMIT :APL0:

Scanning error before '].id DESC LIMIT ...' when parsing: SELECT [Role].* FROM [Role] INNER JOIN [RoleAccount] ON [RoleAccount].[role_id] = [Role].[id] WHERE [RoleAccount].[account_id] = :APR0: ORDER BY [].id DESC LIMIT :APL0:

I was wrong, problem with all relations Many-to-Many



8.4k

double check the models' class name

and would help if you include the db schema



103

problem looks hard



300
edited Sep '20

Sorry, this is my fault. I had a problem with overriding relations in the parent model. Problem solved.