If there's already answer to my question then sorry and please point me in the right direction because I can't find anything.
Let's say I have two Bundles. Each bundle has fixures.yml file and loader file.
Loaders and fixtures are working fine when they are not depending on each other.
However when I am referencing fixtureA from fixtureB I get duplicated record in database.
E.g:
user_{1..10}:
email (unique): '<firstName()>+<randomNumber()>#gmail.com'
plainPassword: 'secret'
story_{1..10}:
user: "#user_<current()>"
title: '<word>'
When they are in separated files - duplicated row. When they are in the same file everything is ok.
Why it's being loaded twice?
I even tried this:
$objects = Fixtures::load(__DIR__ . '/fixtures.yml', $manager, ['persist_once'=>true]);
No luck.
Evey time I am trying to use user object in story fixtures alice tries to save it into db again.
Best Regards,
Robert
I did a little research and talked to people - it looks like it's a possible bug. You can learn more here:
Nelmio/Alice 2.x Duplicated Row
Also I would like to share my work around:
I wanted to keep things separated and clean. Instead of keeping all fixtures in one file in one bundle you can move it to App/DataFixtures/ORM directory. However Symfony will not look for fixtures in this directory. You can:
add path to the fixtures in console command:
doctrine:fixtures:load --fixtures=/var/www/story/app/DataFixtures/ORM
create alias for above solution
override DoctrineFixturesBundle - how to do this
I hope this will help if you have similar issue.
I am working with symfony. I have an entity Check. It has a relation field part.
The definition is something like:
/** #ORM\OneToMany(targetEntity="Power\SelfBundle\Entity\Friends", mappedBy="check")*/
protected $part1;
In the inverse relation (at Friendsentity) the declaration is like:
/** #ORM\ManyToOne(targetEntity="Power\SelfBundle\Entity\Check", inversedBy="part1") */
public $check;
Now for removing ambiguity I have deleted the field and replaced it by part. I have updated the schema and cleared the cache and logs.
Later I am inserting into the friends entity (table infact) and it gives an error while event calling the entity:
1/1ReflectionException: Property Power\SelfBundle\Entity\Check::$part1 does not exists
But $part1 is deleted long ago. The cache is cleared and the log is cleared too. I have searched the whole project but nowhere even the text part1 is found.
I am out of my wit!!
Can anyone please help me!!
Thanks.
The problem is fixed after lots of researching.
The problem was in doctrine metadata cache.
In my config.yml file metadata_cache_driver was set to use APC. So clearing the doctrine app/cache was not helpful.
After lots of searching - I have done
php -r "apc_clear_cache(); apc_clear_cache('user'); apc_clear_cache('opcode');"
and BINGO it worked!!
So in my config_dev.yml I have overridden the setting to set the metadata_cache_driver to array.
I would like to know of any guidelines to use input argument vs input options for passing in data to the symfony console command.
http://symfony.com/doc/current/components/console/introduction.html
I think arguments are to be used when the passed data is required for the command to execute, else use options.
Can you guys throw more light on this? What's the standard ?
I would suggest use Arguments when You want to specify excecution-required values, like:
bin/console vendor:delete-entity 120
but not
bin/console vendor:delete-entity --id=120
You can use Options, when You want to alter the default execution scenario, like:
bin/console vendor:delete-entity 120 --dump-sql
or
bin/console vendor:bulk-create something --batch-size=100
I am trying to use ACL for my project, I have not done it before. I know only the concepts, what it is and why to use it.
I run this command :
$ php app/console init:acl
and I got five tables in my database .
My question is how to use these tables, means how data will be inserted in these tables .
I also have followed steps from here
and still not getting the hang of it , please help me out .
You should'nt use table directly (but you already know), but ACL Entities instead (but it's tricky).
Some people worked on bunbles to simplify those actions. Here is an example on how to use it :
https://github.com/Problematic/ProblematicAclManagerBundle
$comment = new Comment(); // create some entity
$aclManager = $this->get('problematic.acl_manager');
// Adds a permission no matter what other permissions existed before
$aclManager->addObjectPermission($comment, MaskBuilder::MASK_OWNER, $userEntity);
// Replaces all current permissions with this new one
$aclManager->setObjectPermission($comment, MaskBuilder::MASK_OWNER, $userEntity);
$aclManager->revokePermission($comment, MaskBUILDER::MASK_DELETE, $userEntity);
$aclManager->revokeAllObjectPermissions($comment, $userEntity);
You can apply permission on objects or directly on classes (upper level)
I go with Symfony2 docs. It's said that adding
/**
* #ORM\Entity(repositoryClass="Acme\StoreBundle\Entity\ProductRepository")
*/
in my entity file and running php app/console doctrine:generate:entities Acme should create the ProductRepository file. It doesn't. I can't clarimy this more, it's just doesnt create that file, just recreates those entity files that were there before.
I found the answer here:
http://brentertainment.com/other/docs/book/doctrine/orm.html
If you have already generated your entity class before adding the repositoryClass mapping, you have to create the class on your own. Fortunately, it’s pretty easy. Simply create the class in the Repository directory of your bundle and be sure it extends Doctrine\ORM\EntityRepository. Once you’ve created the class, you can add any method to query your entities.
Simple, we have to do it by hand because we have already run this once
If you are using orm.yml files to generate your entities, you can define the repositoryClass, and then generate the entities again:
Acme\StoreBundle\Entity\Product:
type: entity
table: product
...
repositoryClass: Acme\StoreBundle\Entity\ProductRepository
...
And then run:
php app/console doctrine:generate:entities AcmeStoreBundle
You can try to specify a particular bundle:
php app/console doctrine:generate:entities AcmeStoreBundle
Note that i have the full bundles name.
This would help even if you run doctrine:generate:entities before.
Super easy solution to this:
Generate an entity if you haven't already:
php app/console doctrine:generate:entity --entity="AppBundle:EntityName" --fields="id:string(255) content:text(100)"
Now modify these comment lines to your previously generated Entity:
* #ORM\Table(name="TABLENAME")
* #ORM\Entity(repositoryClass="AppBundle\Entity\EntityNameRepository")
Now, just run:
php app/console doctrine:generate:entities AppBundle:EntityNameRepository
Now you have an entity and repository. :)
To get rid of this problem and generate repo classes, you can temporary modify the end of the following file :
symfony\vendor\doctrine\doctrine-bundle\Doctrine\Bundle\DoctrineBundle\Command\generateEntitiesDoctrineCommand.php
if ($m->customRepositoryClassName
&& false !== strpos($m->customRepositoryClassName, $metadata->getNamespace())) {
$repoGenerator->writeEntityRepositoryClass(
$m->customRepositoryClassName, $metadata->getPath());
}
with the following code :
if (true) {
$output->writeln(
sprintf(' > AND Repository <comment>%s</comment>', $m->name . "Repository")
);
$repoGenerator->writeEntityRepositoryClass(
$m->name . "Repository", $metadata->getPath());
}
Some explanations : in this code,
the if condition is simplified with 'if (true)' (and could finally be completely suppressed if you want)
$m->customRepositoryClassName is replaced by $m->name."Repository"
I added some output to be well informed (in the terminal window) when the repo files are generated.
If you don't use the 'if(true)' condition, and want to check things by yourself, you can also add a facultative else case with an output to get well informed in the future :
else {
$output->writeln(sprintf(' > NO repository generated for this class'));
}
After the modifications, you can re-run the command as usual :
php app/console doctrine:generate:entities AcmeStoreBundle
This is a temporary code, because the problem is not very clear for me until now, the only things I see is that it seems to come from $m->customRepositoryClassName which returns an empty string.
So, to find another and definitive solution, a way could be to check the method customRepositoryClassName of the metadata object...
based in Astucieux's answer:
if (true) {
$fullRepositoryClassName = $name . "\\Repository\\" . $basename . "Repository";
$output->writeln(
sprintf(' > AND Repository <comment>%s</comment>', $fullRepositoryClassName)
);
$repoGenerator->writeEntityRepositoryClass(
$fullRepositoryClassName, $metadata->getPath());
}