Comments (4)
Ok, this is not a bug (it's a feature!)
When you have an index on multiple columns, the index can be used by the database if it is used in the correct order.
If your index is defined on columns [A, B, C], then you can use the index to filter upon:
- column A,
- column A and B
- column A, B and C.
If you perform a query on column B alone, the database cannot use the index (because the data is first ordered on column A). For more details: https://dev.mysql.com/doc/refman/8.0/en/multiple-column-indexes.html
So TDBM behaviour is correct. For the index to be used, the left most column of the index MUST be used.
The other columns are optional.
from tdbm.
Question 2 : If the first FK is nullable, I should be able to query the same function by passing null for the nullable column :
Ok, this issue is legit. We should put a '!' on the field.
from tdbm.
... but now we have a problem.
findOneByAandBandC(A $a = null, ?B $b = null, ?C $c = null)
Let's imagine all 3 foreign keys are nullable.
When I call findOneByAandBandC(null, null)
, do I want a query that does "WHERE A_ID IS NULL" or do I want a query that does: "WHERE A_ID IS NULL AND B_ID IS NULL" ???
According to what we said, if I write findOneByAandBandC(null, null)
, we should do "WHERE A_ID IS NULL" but if I write findOneByAandBandC(null, null, $c)
, then the presence of the last parameter makes the second parameter behave as a "IS NULL" and we should go for "WHERE A_ID IS NULL AND B_ID IS NULL AND C_ID = :cid"
The problem is that the "null" meaning is ambiguous. In case of the first parameter, it is easy to assess we want a "IS NULL" (otherwise, we would call the "findAll" method, but for subsequent parameters, we cannot really know.
We could of course call "function_get_params" to know the exact number of parameters passed but I'm a bit reluctant to have 2 different behaviours between findOneByAandBandC($a)
and findOneByAandBandC($a, null)
.
from tdbm.
The meaning of the "null" parameter must not be different based on the position of the parameter (first or not first parameter) in the method, otherwise, this will be error prone for users.
The behaviour of null must stay the same: no filter. If one wants a filter on "IS NULL", it is always possible to override the method.
from tdbm.
Related Issues (20)
- `findFromRawSql` count issue HOT 1
- Index not pass when making a query to database HOT 1
- Add a default guard on data too long for column sql error
- Multiple column FKs HOT 2
- Make sure TDBM uses tdbm.lock at runtime to access the schema
- Working with generated columns HOT 1
- Reminder: Switch back to ^1.0.5 of brain-diminished/schema-version-control when it is tagged
- TDMService event listening system
- Bug when generating Dao from a database with uppercase table names HOT 1
- Not install width PHP 8
- UniqueEntity Annotation
- Lines duplicated when ordering on a n-n join table using find() method in the DAO HOT 2
- Update deprecated use of ZendFramework
- 5.2: `ResultIterator::getIterator()` `@method` declaration is wrong
- Enhancement: Merge multiple ResultIterator objects into one
- ManyToManyRelationshipPathDescriptor::getPivotFrom method doesn't escape the name of the "FROM" table
- Integration with Slim framework HOT 1
- Self referencing ManyToMany issue
- Fatal error while generating entities on php 8.1 HOT 1
- PHP's interface typing changes
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 tdbm.