Comments (8)
$repository->select()->subquery([
'myAwesomeAlias' => function(QueryBuilder $qb){
$qb->from($tableName)->columns('field1', 'field2');
}
]);
SELECT myAwesomeAlias.field1, myAwesomeAlias.field2, related.*
FROM (
SELECT table1.field1, table1.field2
FROM table1
WHERE table1.field3 = 'value'
LIMIT 10 OFFSET 10
) as myAwesomeAlias
LEFT JOIN related ON related.table1_id = some_alias.field1
$repository->select()->subquery(function(QueryBuilder $qb){
$qb->from($tableName)->columns('field1', 'field2')->
where(['field3'=>'value'])->limit(10)->offset(10);
})->load('related', ['method'=>LEFT_JOIN, 'load'=>...]);
SELECT some_alias.field1, some_alias.field2, related.*
FROM (
SELECT table1.field1, table1.field2
FROM table1
WHERE table1.field3 = 'value'
LIMIT 10 OFFSET 10
) as some_alias
LEFT JOIN related ON related.table1_id = some_alias.field1
If not existed $qb->from($tableName)
, then by default $tableName
is current tableName
in select
.
$anotherSelect = $table3Repository->select()->columns(['field1' => 'some_field1', 'field2' => 'some_field2']);
$table1Repository->select()->subquery(function(QueryBuilder $qb) use($anotherSelect){
$qb->addSelect($anotherSelect);
});
SELECT some_alias.field1, some_alias.field2
FROM (
SELECT table3.some_field1 AS field1, table3.some_field2 AS field2
FROM table3
) as some_alias
But this select is going to resolve table1Entity fields. This behaviour can be useful for materialized views, I think, or something like that. Or just for refactoring/customization purposes.
from orm.
Add possibility for generating subqueries in core
Already exist in DBAL.
Sync column aliases from subquery or parent query
Already exists in DBAL.
Need to create new fetch method though.
from orm.
If you provide some information about it, I'll do merge request tomorrow.
from orm.
Honestly, that's something for me personally. Take a look at Select/Loader functionality first.
from orm.
Can you give examples of sql produced? I can help with pin-pointing the location.
from orm.
Try $select->from($insertQueryHere)
. How close is that to what you want, if it is we will make better syntax for it. Shouldn't be hard.
from orm.
Yeah, this is some hack issue for me, but it's works.
Problem with this solution - you need to interpolate the query and manually resolve table aliases.
$select = $orm->getRepository()->select();
$params = new QueryParameters();
$sqlStatement = $select->buildQuery()->sqlStatement($params);
$sqlStatement = Interpolator::interpolate($sqlStatement, $params->getParameters());
$resultStatement = preg_replace('/\sAS\s\"c\d+\"/', '', $sqlStatement);
$select = $select->from(
(new Fragment('(' . $resultStatement . ') as "' .
$select->getBuilder()->getLoader()->getAlias() . '"'))
);
from orm.
Good, so this is the baseline.
from orm.
Related Issues (20)
- Update badges HOT 1
- 🐛 PHP 8.3
- CTE support for QueryBuilder HOT 1
- 🐛 fkAction/fkOnDelete has no effect for automatically created migrations HOT 1
- 💡 Add options set for auto-generated column values
- Cascade Persist Fails without cloning object in softDelete Method
- 💡 Cycle schema hydration is too slow
- 🐛 HasOne. select by relation property generates unnecessary INNER JOIN HOT 3
- Expected parameter of type 'Cycle\Annotated\Locator\EmbeddingLocatorInterface', 'Spiral\Tokenizer\ClassLocator' provided HOT 2
- Check useless `order by` on some ORM prefetches
- Index Names Not Applied to Database When Using Annotations HOT 1
- 💡 Embeddable Behaviors
- 💡 Allow setting enum cases as property defaults
- 🐛 In changelog version 2.8 is missed
- 💡 Ability to use `with` more than once with same relation. For several JOINs HOT 1
- 🐛 Issue with Enum Field Difference Detected During Database Migration Synchronization
- 💡 Efficient bulk-loading of morph relations
- 🐛 Self transation cannot be resolved. HOT 4
- Duplicate entry for primary key 🐛 HOT 4
- 💡 Add documentation for migration generation / drivers HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from orm.