Ticket #321 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

Support aliases with QQ

Reported by: VexedPanda Owned by: somebody
Priority: important Milestone: 1.1.2
Component: QQuery Version: 1.0.0 Stable
Keywords: Cc:

Description

Right now, there's no way in QQ to accomplish the following query without using SubSQL:

select u.* from users as u
left join project_user_assn as pu1 on pu1.user_id = u.id
left join project_user_assn as pu2 on pu2.user_id = u.id
where
pu1.project_id = 1
and 
pu2.project_id = 2

Perhaps syntax like this?

QQ::AndCondition(
QQ::Equal(QQ::Alias(QQN::User(), Projects, 'pu1')->ProjectId, 1),
QQ::Equal(QQ::Alias(QQN::User(), Projects, 'pu2')->ProjectId, 2)
)

QQ::Alias would simply return a QQNode, so the rest of the code would be unchanged, it would just be smart enough to realize that the pu1 alias and the pu2 alias should result in different aliases for the join (QQN::User() to QQN::User()->Projects) passed in.

Attachments

ticket321.patch Download (5.7 KB) - added by VexedPanda 2 years ago.
Here's a working patch
ticket321o2.patch Download (5.8 KB) - added by VexedPanda 2 years ago.
Ok, here's option two. I think this is a lot cleaner, and so far seems just as solid. We should make some test cases and example code. :)
ticket321-example.patch Download (2.8 KB) - added by VexedPanda 2 years ago.
Here's an example. Same as above.
patch321_v4.patch Download (15.3 KB) - added by alex94040 2 years ago.
New combined patch. Includes code, examples, and tests

Change History

Changed 2 years ago by VexedPanda

  • milestone changed from 2.0 to 1.2

Progress is being made. Moving to 1.2.

Changed 2 years ago by VexedPanda

Here's a working patch

Changed 2 years ago by VexedPanda

  • status changed from new to in_QA

So the downside to this approach is that I basically had to copy/paste GetColumnAliasHelper? from the three base QQNode types (QQNode, QQAssociationNode, and QQReverseReferenceNode), leading to a lot of code duplication.

I'll try another approach and see if it's cleaner.

That said, this seems to work beautifully. :)

Changed 2 years ago by VexedPanda

Ok, here's option two. I think this is a lot cleaner, and so far seems just as solid. We should make some test cases and example code. :)

Changed 2 years ago by VexedPanda

Syntax for both options is:

User::QueryArray(
  QQ::AndCondition(
    QQ::Equal(QQ::Alias(QQN::User()->Projects, 'pu1')->ProjectId, 1),
    QQ::Equal(QQ::Alias(QQN::User()->Projects, 'pu2')->ProjectId, 2)
  )
);

This will return a list of all users who are in both project 1 and 2.

Changed 2 years ago by alex94040

  • milestone changed from 1.2 to 1.1.2

Changed 2 years ago by alex94040

Vexed - do you want to write up an example, and I'll do the unit tests?

Changed 2 years ago by VexedPanda

Sure. I should have time for that tomorrow. :)

Changed 2 years ago by VexedPanda

Here's an example. Same as above.

Changed 2 years ago by VexedPanda

Any feedback / tests on this?

Changed 2 years ago by alex94040

So sorry, I have been slacking. Difficult personal time for me this past month (and will be most of next month). I'm buying a house, and it's a huge pain in the rear. But I will come back and take care of this!

Changed 2 years ago by VexedPanda

Sorry, definitely didn't mean to sound accusitory. :)
That's great! Congratulations! I bought my first house about a year and a half ago, and it was pretty stressful, so I know what that's about. :)

Changed 2 years ago by alex94040

New combined patch. Includes code, examples, and tests

Changed 2 years ago by alex94040

OK, so here's a combined patch. Summary:
1) No code modifications
2) Expanded the example a little bit - added another, slightly more complex, instance of QQ::Alias() use.
3) Wrote new tests for QQAlias.
4) Refactored some of the shared functionality between the new tests and what we had in ExpandAsArray? tests into the base QCubed Unit Test Case class.

Please review! Let's remember to commit this to both 1.1 and 2.0.

Changed 2 years ago by VexedPanda

I didn't re-check the alias code, but the new example and test code looks great. :)

Changed 2 years ago by VexedPanda

Any word on this? If it's ready to commit, I think it'd be a great new feature for 2.0.1. :)

Changed 2 years ago by alex94040

I think this is ready to commit.

Changed 2 years ago by VexedPanda

  • status changed from in_QA to closed
  • resolution set to fixed

(In [914]) Fixes #321

Changed 2 years ago by VexedPanda

(In [915]) Fixes #321 for v2.0.1

Note: See TracTickets for help on using tickets.