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

Query main model with related model criteria

My question is simple, atleast, I tought.

Given the following situation

> CREATE TABLE `robots` (
>     `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
>     `name` varchar(70) NOT NULL,
>     `type` varchar(32) NOT NULL,
>     `year` int(11) NOT NULL,
>     PRIMARY KEY (`id`)
> );
> 
> CREATE TABLE `robots_parts` (
>     `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
>     `robots_id` int(10) NOT NULL,
>     `parts_id` int(10) NOT NULL,
>     `created_at` DATE NOT NULL,
>     PRIMARY KEY (`id`),
>     KEY `robots_id` (`robots_id`),
>     KEY `parts_id` (`parts_id`)
> );
> 
> CREATE TABLE `parts` (
>     `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
>     `name` varchar(70) NOT NULL,
>     PRIMARY KEY (`id`)
> );

I would like to query Robots for all the robots that have a Part called "lasers" for example. The documentation doesn't state anything on this subject.

Seems to be a simple where clause, but is it possible to achieve this without making a custom query?

To my knowledge, is not possible by default. You can use query builder

I've edited the original post to make the syntax highlighted nicely. @bw-delano, "edit" your post to see the simple changes I made.