Comments (7)
@easy-cloud what does your entity look like? Because the identifier should always be there in an entity...
from doctrinemodule.
/**
* @ORM\Id
* @ORM\Column(type="integer",unique=true);
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
this is my identifier, in all entities it is the same.
from doctrinemodule.
By looking at https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L645-677 it seems that your identifier is not set. Are you able to get a piece of code showing how you use the form?
from doctrinemodule.
$this->add(array(
'name' => 'location_id',
'type' => 'DoctrineORMModule\Form\Element\DoctrineEntity',
'options' => array(
'label' => 'Location',
'object_manager' => $em,
'target_class' => '\StadEnNatuur\Entity\Location',
'property' => 'name'
),
));
from doctrinemodule.
I'm experiencing same issue with Doctrine ORM/DBAL 2.3.0 and DoctrineModule/DoctrineORMModule (dev). It appears when I'm using associated entities:
User Entity
class User
{
/**
* @ORM\Id
* @ORM\Column(type="integer", name="id")
* @ORM\GeneratedValue
*/
protected $id;
...
/**
* @ORM\OneToOne(targetEntity="Country")
* @ORM\JoinColumn(name="country_id", referencedColumnName="id", nullable=true)
*/
protected $country;
...
/**
* @return Application\Entity\Country
*/
public function getCountry()
{
return $this->country;
}
...
}
Country Entity
class Country
{
/**
* @ORM\Id
* @ORM\Column(type="integer", name="id", nullable=false)
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\Column(type="string", name="name", nullable=true)
*/
protected $name;
}
If I request Country associated with already requested User in database - getIdentifierValues returns empty array. For example (user 1 is associated with country 2):
$user = $entityManager->getRepository('Application\Entity\User')->find(1);
$country = $entityManager->getRepository('Application\Entity\Country')->find(2);
$metadata = $entityManager->getClassMetadata(get_class($country));
$countryId = $metadata->getIdentifierValues($country);
var_dump($countryId); // array(0) {}
Same result with getter:
$user = $entityManager->getRepository('Application\Entity\User')->find(1);
$country = $user ->getCountry();
$metadata = $entityManager->getClassMetadata(get_class($country));
$countryId = $metadata->getIdentifierValues($country);
var_dump($countryId); // array(0) {}
But if I request country that not associated with any requested entity it is OK (Country 1 not associated with any loaded User entities):
$country = $entityManager->getRepository('Application\Entity\Country')->find(1);
$metadata = $entityManager->getClassMetadata(get_class($country));
$countryId = $metadata->getIdentifierValues($country);
var_dump($countryId); // array(1) {["id"] => int(1)}
I've tried with one-to-one unidirectional association.
I think it must be checked on clean Doctrine ORM...
from doctrinemodule.
Closing as duplicate of #122
This will be fixed with Doctrine ORM 2.4
from doctrinemodule.
A question for @sergej-kurakin:
When using your example and adding my form element the way @easy-cloud did with location and I try to flush my entity I get the following error:
Catchable fatal error: Argument 1 passed to Application\Entity\Address::setCountry() must be an instance of Application\Entity\Country, string given
Entity and form seem to be correct. It looks like I am missing some kind of hydration to make ZF2 pass the object identifier instead of the posted form value. How did you manage this?
from doctrinemodule.
Related Issues (20)
- vendor/bin/doctrine-module only works if it's a symlink HOT 12
- Unit tests should be executed with PHP 8.0 HOT 1
- Pushed breaking change in 4.2 release HOT 4
- incompatible with doctrine/orm >= 2.12.0 HOT 3
- Missing Versions on Packagist HOT 2
- Deprecate doctrine/cache HOT 8
- Release 5.3.0 with PHP 8.2 Support HOT 5
- Can't install due to conflicting requirements HOT 25
- Current CLI implementation triggers api-tools-mvc-auth events HOT 2
- 6.0.2 regex change is too restrictive HOT 6
- Missing requirement in composer.json HOT 2
- Migration to v6 leads to cache issues HOT 11
- Authentication Error when no credentialCallable is given. HOT 5
- Allow cleanSearchValue method to accept an integer HOT 4
- Mapping error doctrine find, findOneBy, findBy. HOT 1
- Package incorrectly states that it does provide `laminas/laminas-cache-storage-implementation` HOT 3
- Bump to PHP 8.3 ? HOT 3
- orm3 compatibility HOT 1
- Implement CacheItemPoolInterface
- Upgrade to ServiceManager 4 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 doctrinemodule.