Comments (11)
I'm having the exact same problem. Did you find a workaround (other than just ignoring those errors)?
from phpstan-doctrine.
No I didn't find a good solution. I gived up and add it to the ignored errors :/
from phpstan-doctrine.
I will try to look into it.
from phpstan-doctrine.
Thanks for replying @noemi-salaun I've ended up doing the same. Also thanks @lookyman - really appreciate it 😄
from phpstan-doctrine.
I have a similar issue, except my use-case is the opposite - I have a non-nullable database field, but need the property itself to be nullable for creation (and then use a NotNull
assert to prevent possible issues).
from phpstan-doctrine.
@noemi-salaun I have the same, but with an additional @ORM\JoinColumn(nullable=false)
on UserStats::$user
. This tells Doctrine that there can be no UserStats
with an empty user
column. This aspect might already be included in @ORM\Id
though ;-)
I think the real problem is: From looking at the mapping, you cannot answer the following question:
When a
User
is created, will there be aUserStats
created in any case?
...cause the mapping does allow a User
without a UserStats
. In my app, I can answer with YES, cause in User
s constructor I have:
$this->setStats(new UserStats($this));
... and cascade={"persist"})
on User::$stats
.
@lookyman Checking for those two aspects might be an idea to resolve this.
Doctrine docs: https://www.doctrine-project.org/projects/doctrine-orm/en/2.8/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity
from phpstan-doctrine.
I have a similar problem
class Order
{
/**
* @var int
*
* @ORM\Id()
* @ORM\GeneratedValue(strategy="IDENTITY")
* @ORM\Column(name="id", type="integer", nullable=false)
*/
private $id;
/**
* @var Billing
*
* @ORM\OneToOne(targetEntity="Billing", mappedBy="order", orphanRemoval=true, cascade={"persist"})
*/
private $billing;
// ...
}
class Billing
{
/**
* @var int
*
* @ORM\Id()
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var Order
*
* @ORM\OneToOne(targetEntity="Order", inversedBy="billing")
* @ORM\JoinColumn(name="order_id", referencedColumnName="id", nullable=false)
*/
private $order;
/**
* @var int
*
* @ORM\Column(name="order_id", type="integer", nullable=false)
*/
private $orderId;
// ....
}
PHPStan error message:
Property Order::$billing type mapping mismatch: database can contain Billing|null but property expects Billing
from phpstan-doctrine.
@mitelg If there's no Billing for order ID 123 in the database, the $billing
property for Order 123 will be null.
from phpstan-doctrine.
@ondrejmirtes thanks for your reply
but an order without billing is not valid and should/could not happen 🤔 at least, I hope so 😅🙈
is there a way to ensure that?
I would have to look it up tomorrow, but on DB level, this should be prevented.
from phpstan-doctrine.
I think it can't be enforced on the DB level.
from phpstan-doctrine.
hey @ondrejmirtes
I had a deeper look in the code, and the order and the billing are created directly via SQL 🙈
So due to erroneous behaviour at some point, it could indeed be possible that an order has no billing in the respective doctrine model 😬
legacy software is fun... 🎉
thank you very much again!
from phpstan-doctrine.
Related Issues (20)
- Performance issues after 1.3.54 HOT 19
- PHPStan crashes if Doctrine Column is a UnitEnum (PHPStan+Doctrine extension) HOT 2
- False Possitive in Abstract Respoitory classes mapped to Abstract Entity classes: "<entity> has no field or association named <field>" HOT 5
- Comparing the database mapping type to the property type should take the phpstan level into account HOT 2
- Compatibility with doctrine/orm:3 HOT 9
- doctrine/orm v3 - Declaration of ClassMetadataFactory::newClassMetadataInstance($className) HOT 4
- Incorrect PHPStan Error for Method Return Type Declaration HOT 2
- Enforce `Connection::executeQuery` on SELECT and `Connection::executeStatement` on others queries HOT 7
- Repository methods considered pure
- support for doctrine/orm 3+? HOT 6
- Query analyser gets confused when a join alias is equal to the relation name
- Use DTO in a query builder HOT 7
- Add UniqueEntity constraint field validation
- False positive when working with ArrayAccess HOT 21
- Since v1.3.64: Interface "PHPStan\Classes\ForbiddenClassNameExtension" not found HOT 6
- Incompatible bleedingEdge Connection stub typehint with DBAL 4 HOT 5
- Report an error for QueryBuilder::setParameter without specifying the Type. HOT 10
- Query result type is not recognized if the alias is `"attribute"`
- Autogenerated id column should be positive-int HOT 4
- Symfony PdoSessionHandler + Doctrine: Property $sessId is never written, only read. HOT 3
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 phpstan-doctrine.