this my entity class
<?php
namespace Application\MainAppBundleBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Oryzone\Bundle\MediaStorageBundle\Entity\Media as BaseMedia;
/**
Application\MainAppBundleBundle\Entity\Media *
#ORM\Table(name="media")
#ORM\Entity() */
class Media extends BaseMedia
{
/**
* #ORM\Id
* #ORM\Column(name="id", type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* {#inheritDoc}
*/
public function getId()
{
return $this->id;
}
}
?>
when i execute "php app/console doctrine:update:schema --force" i get this message
nothing to update ...
help please
Resolved ✔
the problem: when I execute doctrine:schema:update, the update of the data base is based on the files in # MyBundle / Resources / config / doctrine / MyFiles.orm.yml since I created my entity Entity / media.php and I have not Media.orm.yml the media table will not be created, so I deleted all files * orm.yml and I execute php app / console doctrine.: schema: update and the table is created
#hourss2040
I think you can't combine .orm.yml and annotations in same Entity.
Try to switch auto mapping on like this:
doctrine:
orm:
auto_mapping: true
Or register your bundle mapping like this:
doctrine:
orm:
entity_managers:
default:
connection: default
mappings:
MainAppBundleBundle: ~
Related
I've followed the directions on this page:
https://symfony.com/doc/current/doctrine/multiple_entity_managers.html
And my doctrine.yaml file looks like:
doctrine:
dbal:
default_connection: one
connections:
one:
# configure these for your database server
url: '%env(DATABASE_ONE_URL)%'
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
two:
# configure these for your database server
url: '%env(DATABASE_TWO_URL)%'
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
orm:
default_entity_manager: one
entity_managers:
one:
connection: one
mappings:
One:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/One'
prefix: 'App\Entity\One'
alias: One
two:
connection: two
mappings:
Two:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Two'
prefix: 'App\Entity\Two'
alias: Two
I've got a One and Two directory inside my Entity directory with a simple Entity class in both:
A Person in One:
<?php
namespace App\Entity\One;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="person")
*/
class Person
{
/**
* #var int
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
* #ORM\Column(type="integer")
*/
private $id;
/**
* #var string
*
* #ORM\Column(type="string")
*/
private $name;
{Getters and setters ...}
}
A Post in Two:
<?php
namespace App\Entity\Two;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="post")
*/
class Post
{
/**
* #var int
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
* #ORM\Column(type="integer")
*/
private $id;
/**
* #var string
*
* #ORM\Column(type="string")
*/
private $title;
{Getters and setters ...}
}
When I run bin/console doctrine:migrations:diff and bin/console doctrine:migrations:migrate the Person is added to the One database correctly.
When I run bin/console doctrine:migrations:diff --em=two and bin/console doctrine:migrations:migrate --em=two both this and the Person migration for One are executed and the Two database has both a Person and a Page table.
I can't seem to figure out where I'm going wrong with this
I want to expose only a few properties of my User class, using JMSSerializerBundle and FOSRestBundle.
It seems like the serializer bundle is not reading my configuration file.
My User class is in src/AppBundle/Entity/User and it extends the FOSUserBundle user class.
Here is my User class:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Symfony\Component\Validator\Constraints as Assert;
/**
* User
*
* #ORM\Table(name="backoffice_user")
* #ORM\Entity(repositoryClass="AppBundle\Entity\Repository\UserRepository")
*/
class User extends BaseUser
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
*
* #ORM\Column(name="lastname", type="string", length=70)
*/
private $lastname;
/**
* #var string
*
* #ORM\Column(name="firstname", type="string", length=70)
*/
private $firstname;
}
This is my app/config.yml file
jms_serializer:
metadata:
debug: true
auto_detection: true
And the yml mappgin file in src/AppBundle/Resources/config/serializer/Entity.User.yml :
AppBundle\Entity\User:
exclusion_policy: ALL
exclude: true
properties:
email:
exclude: true
expose: true
The file is not read (or at least not taken into account), because my API returns me all fields of my entity.
Am I forgetting something ?
Your mapping file is not loaded, because the serializer applies the rules to the class where the properties are defined. In your case - that is FOS\UserBundle\Model\User. What you need is to override the Third-Party Metadata - a brief sample can be seen in bundle's documentation
In your config.yml, jms_serializer should probably look like this:
jms_serializer:
metadata:
auto_detection: true
directories:
FOSUserBundle:
namespace_prefix: "FOS\\UserBundle"
path: "#AppBundle/Resources/config/serializer"
Inside directory serializer you should have a file named Model.User.yml with configuration like this:
FOS\UserBundle\Model\User:
exclusion_policy: ALL
# add your desired configuration below.
In JMSSerializer you need to have one file for each class of the hierarchy.
So, the exclusion policy only apply to properties id, lastname and firstname; for BaseUser it use the default rule, which is to include everything.
To override a configuration file from another bundle, you first need to setup the folder for the namespace in the configuration with:
jms_serializer:
metadata:
directories:
FOSUB:
namespace_prefix: "FOS\\UserBundle"
path: "%kernel.root_dir%/serializer/FOSUB"
And add the serializer config file in app/serializer/FOSUB/Model.User.yml. See the official docs for other configurations option.
I would like to ask you how it si possible to implement the sortable repository for gedmo sortable extension into symfony 2. I am a little confused how to inject the EntityManager and ClassMetadata into the constructor and how the repository register correctly in services.yml and entity.
Here is the repository:
https://github.com/l3pp4rd/DoctrineExtensions/blob/master/lib/Gedmo/Sortable/Entity/Repository/SortableRepository.php
Thank you very much!
I recommend you install the StofDoctrineExtensionsBundle
And you can enable the sortable behavior in your config file.
Example:
config.yml
stof_doctrine_extensions:
orm:
default:
sortable: true
Entity class
/**
* Acme\Bundle\ProjectBundle\Entity\Foo
*
* #ORM\Table
* #ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
*/
class Foo
{
/**
* #var integer $position
*
* #Gedmo\SortablePosition
* #ORM\Column(name="position", type="integer")
*/
private $position;
}
Remember to subscribe GedmoListener on boot()
<?php
class AcmeBundle extends Bundle
{
$em = $this->container->get('doctrine.orm.default_entity_manager');
$evm = $em->geteventmanager();
$evm->addeventsubscriber(new \gedmo\sortable\sortablelistener);
}
I want to extend default user entity attributes. In database after extending FOSUserBundle with SonataUserBunle there are 2 tables for storing users: fos_user and fos_user_user. I want to extend fos_user
Here is app/AppKernel.php:
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
in app/config.yml file I set:
fos_user:
db_driver: orm<br>
firewall_name: main<br>
user_class: Acme\DemoBundle\Entity\User<br>
group:<br>
group_class: Application\Sonata\UserBundle\Entity\Group<br>
sonata_user:
security_acl: true
class:
user: Acme\DemoBundle\Entity\User
admin:
user:
class: Acme\DemoBundle\Admin\UserAdmin
parameters:
sonata.user.admin.user.class: Blogger\BlogBundle\Admin\UserAdmin
sonata.user.admin.user.entity: Blogger\BlogBundle\Entity\User
doctrine:
orm:
auto_mapping: auto
SonataUserBundle is created in src/Application/Sonata/UserBundle
To override SonataUserBundle, i extended UserAdmin by creating another UserAdmin class in src/Acme/DemoBundle/Admin/UserAdmin and all works fine
Now I want to extend User entity (fos_user table) to add new attributes.
Here is my Acme/Demo/Entity/User.php that I want to extend the default User entity
namespace Acme\DemoBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/*
* #ORM\Column(type="string", name="newAttribute")
*/
protected $newAttribute;
public function __construct()
{
parent::__construct();
// your own logic
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
}
What should I do to extend default fos_user table with php app/console doctrine:generate:entities Acme/DemoBundle
I've read many posts about this issue but none of the solutions helped me. I tried to extend Model class instead of Entity class but also nothing changed
You don't have to.
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle')
Here your are telling the SonataUserBundle to use the FOSUserBundle as well.
Then in your User entity you set:
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="User")
*/
class User extends BaseUser
Because you have said to the SonataUserBundle "use the fosuserbundle" and you extend from the sonata user bundle user entity he's gonna "merge" those 2 models into 1 and add your custom fields from in your user entity as well.
I am trying to sort by a property which is not in relation but part of current entity.
For some reason sortable wont work for me if property with #Gedmo\SortableGroup is part of current entitty.
Here is my Entity:
https://gist.github.com/rat4m3n/91df50da8c653edfa3d0
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* #Gedmo\SortableGroup
* #ORM\Column(name="total_chips", type="integer")
*/
private $total_chips = 0;
/**
* #Gedmo\SortablePosition
* #ORM\Column(name="ranking", type="integer")
*/
private $ranking = 0;
Is this simply not possible / supported ?
Else... how could I accomplish such behaviour in any other way?
If you still have a problem with the SortablePosition and the SortableGroup feature of Gedmo, you can follow this :
Do not affect values to the property.
Activate the features in the config.yml
stof_doctrine_extensions:
default_locale: fr_FR
orm:
default:
sortable: true
tree: true
And add the listener to your entity :
namespace Acme\AcmeBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AcmeAcmeBundle extends Bundle
{
public function boot()
{
$em = $this->container->get('doctrine.orm. default_entity_manager');
$evm = $em->getEventManager();
$evm->addEventSubscriber(new \Gedmo\Sortable\ SortableListener);
}
}