I was able to tame it down a bit
$qb = $this->_em->createQueryBuilder();
$qb->select('service')
->from('Entity\ServiceLineItem', 'service')
->join('service.category', "c")
->where('c.category=:category')
->setParameter('category', 'Other');
I think it's that's the best I can do.
On Tuesday, October 6, 2015 at 12:06:38 PM UTC-4, Dennis Fedco wrote:
>
> I am just starting to use Doctrine again after a long break. I used
> Doctrine before lightly, more so following simple examples in a tutorial.
>
> Now, I am evaluating using it in a real project that uses multiple
> databases and joins that span across several databases and tables. So far
> I am using it for new functionality only.
>
> Functionality is as follows -- given a list of many services, each service
> falls into one of the few categories. To select required service faster,
> users are to select their category first, upon which they are shown
> services from that category only and then they can select appropriate
> service. I've decided to create two entities in this case, ServiceLineItem
> (description), and ServiceCategory. And set up ManyToOne relationship like
> so:
>
> class ServiceLineItem
> {
> /**
> * @ManyToOne(targetEntity="ServiceCategory")
> */
> private $category;
> }
>
> *Task*
> Select all services in ServiceLineItem, with chosen ServiceCategory of
> "Testing".
>
> Using SQL I would do it like so:
> -- Exhibit 1 --
> select *
> from service_line_item
> join service_category on service_line_item.service_category_id =
> service_category.id
> where service_category.category = "Testing";
>
> Or I could do it like so, without the JOIN if I have to:
> $id = ... select id from service_category where category = "Testing";
> --
> select * from service_line_item where service_category_id = $id;
>
> *My problem is as so:*
>
> - My expectations of Doctrine were that there would be a simple
> auto-magical way to retrieve data for a common JOIN pattern like in
> Exhibit
> 1.
> The relationship association is already defined! Might there be an
> extra method to invoke that connection implicitly?
>
> So far, people tell me that I have to write a custom DQL with custom
> class extending EntityRepository and using createQueryBuilder(), where(),
> setParameter() and innerJoin().
> It may be fine and great for extra custom cases, but it is a lot of
> overhead to learn new API and use it in the code especially for something
> fairly common and simple like my use case (I would think).
> I ponder the efforts of learning DQL API when I already know how to
> call an already-complex enough and already-known-to-me SQL directly, with
> mysqli. I see this (DQL, etc) as being potentially more trouble than it's
> worth.
>
> The above has me question how far I want to go into Doctrine if it is
> going to place a lot of custom DQL API into the codebase both for me and
> for others to learn.
>
> Alternatively, it seems it'd be easier to do something like this instead,
> effectively breaking removing the JOIN, avoiding custom DQL, but leaving no
> power for Doctrine....
> Entity\ServiceLineITem
>
> Am I using this correctly? Is there a philosophy behind Doctrine that I
> am missing? Did I perhaps miss a feature?
>
> My trial move towards using Doctrine was in hopes that it will manage SQL
> creation&modification for me (it mostly does), use InnoDB (it does), set up
> FK+Referential Integrity (it does), and simplify data Input/Output (so far
> ... it does not, not to my "lazy programmer" satisfaction)
>
> Thanks!
>
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.