Entity 1
<?php
namespace Operat\SystemBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Operat\AgentsBundle\Entity\Agents;
/**
* Liensao
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Operat\SystemBundle\Entity\LiensaoRepository")
*/
class Liensao
{
// Liensao - Agents
/**
* #ORM\ManyToOne(targetEntity="Operat\AgentsBundle\Entity\Agents", inversedBy="liensao")
* #ORM\JoinColumn(name="colAgent_Code", referencedColumnName="CODE")
*/
protected $agent;
/*....*/
Entity 2
<?php
namespace Operat\AgentsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Operat\SystemBundle\Entity\Liensao;
/**
* Agents
*
* #ORM\Table(name="agents", indexes={#ORM\Index(name="Valide", columns={"Valide"}), #ORM\Index(name="GL", columns={"GL"}), #ORM\Index(name="NSOC", columns={"NSOC"})})
* #ORM\Entity
*/
class Agents
{
// Agents - Liensao
/**
* #ORM\OneToMany(targetEntity="\Operat\SystemBundle\Entity\Liensao", mappedBy="agent")
*/
protected $liensao;
Yet running
php app/console doctrine:schema:update --em=entities_system --dump-sql --force
gives the following error:
[Doctrine\Common\Persistence\Mapping\MappingException]
The class 'Operat\AgentsBundle\Entity\Agents' was not found in the chain configured namespaces Operat\SystemBundle\Entity, Operat\AdministrationBundle\Entity, FOS\UserBundle\Entity
Config.yml
orm:
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: entities_system
entity_managers:
entities_system:
connection: operat_system
mappings:
OperatSystemBundle: ~
FOSUserBundle: ~
entities_agents:
connection: operat_agents
mappings:
OperatAgentsBundle: ~
Related
Is there some examples to implement this? Don't show nothing on my page.
{% include 'FOSCommentBundle:Thread:async.html.twig' with {'id': 'foo'} %}
I don't understand how to place this code and what will show on my page.
And when i place this on my config.yml
assetic:
bundles: [ "FOSCommentBundle" ]
Creates an error:
Unrecognized option "assetic" under "fos_comment".
My configuration:
fos_comment:
db_driver: orm
class:
model:
comment: BackEndBundle\Entity\Comment
thread: BackEndBundle\Entity\Thread
assetic:
bundles: [ "FOSCommentBundle" ]
I assume you have configure the bundle and have created the require classes like this
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\CommentBundle\Entity\Comment as BaseComment;
/**
* #ORM\Entity
* #ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
*/
class Comment extends BaseComment
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* Thread of this comment
*
* #var Thread
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Thread")
*/
protected $thread;
}
And Thread.php like this
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\CommentBundle\Entity\Thread as BaseThread;
/**
* #ORM\Entity
* #ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
*/
class Thread extends BaseThread
{
/**
* #var string $id
*
* #ORM\Id
* #ORM\Column(type="string")
*/
protected $id;
}
In your config.yml, you will now have something like this
fos_comment:
db_driver: orm
class:
model:
comment: AppBundle\Entity\Comment
thread: AppBundle\Entity\Thread
run the following commands
doctrine:cache:clear-metadata
doctrine:schema:update --force
After this you will have tables in the database for the entities
Now include this at top of the template
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
where you've included this
{% include 'FOSCommentBundle:Thread:async.html.twig' with {'id': 'foo'} %}
Clear both dev and prod cache after this step.
PS: I have selected the doctrine ORM method
I am using Symfony 2.8, FOSUserBundle 1.3 and FOSOAuthServerBundle 1.5
For all of the class needed to those Bundles to work, I ended up with doctrine not updating my schema properly. I mean it doesn't take into account the fields from the Base Class.
CREATE TABLE oauh2_access_tokens (id INT NOT NULL, client_id INT NOT NULL, user_
id INT DEFAULT NULL, PRIMARY KEY(id));
CREATE TABLE oauth2_auth_codes (id INT NOT NULL, client_id INT NOT NULL, user_id
INT DEFAULT NULL, PRIMARY KEY(id));
CREATE TABLE oauth2_clients (id INT NOT NULL, PRIMARY KEY(id));
CREATE TABLE oauth2_refresh_tokens (id INT NOT NULL, client_id INT NOT NULL, use
r_id INT DEFAULT NULL, PRIMARY KEY(id));
Here's my config:
doctrine:
orm:
#auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: default
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
COMPANYAuthBundle: ~
fos_user:
db_driver: orm
firewall_name: api
user_class: COMPANY\AuthBundle\Entity\User
#FOSOAuthBundle Configuration
fos_oauth_server:
db_driver: orm
client_class: COMPANY\AuthBundle\Entity\Client
access_token_class: COMPANY\AuthBundle\Entity\AccessToken
refresh_token_class: COMPANY\AuthBundle\Entity\RefreshToken
auth_code_class: COMPANY\AuthBundle\Entity\AuthCode
service:
user_provider: fos_user.user_manager
And here's my class User
<?php
namespace COMPANY\AuthBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Entity\User as BaseUser;
/**
* Utilisateur
*
* #ORM\Table(name="users")
* #ORM\Entity
*/
class User extends BaseUser
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
}
So, yes I did put the right use and not FOS\UserBundle\Model\User as BaseUser;
Same thing for the class of OAuthServerBundle: (I'm just putting one here, they're all following the same pattern)
<?php
namespace COMPANY\AuthBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\OAuthServerBundle\Entity\Client as BaseClient;
/**
* Client
*
* #ORM\Table(name="oauth2_clients")
* #ORM\Entity(repositoryClass="COMPANY\AuthBundle\Repository\ClientRepository")
*/
class Client extends BaseClient
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
public function __construct()
{
parent::__construct();
}
}
Does anybody have an idea why base class' fields aren't put into my db? Thanks :)
Okay, I found the solution after 10 hours of search...
And the solution is to not forget to add FOSUserBundle and FOSOAuthServerBundle and all the base class bundles to your mapping.....
So this should be the config:
doctrine:
orm:
#auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: default
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
COMPANYAuthBundle: ~
FOSUserBundle: ~
FOSOAuthBundle: ~
Also, you can't make a bundle inherit from two bundles if you want to use the routes of each. So, create one bundle for each. Then in each of the Bundle class, add the following function:
public function getParent()
{
return "FOSOAuthServerBundle"; //Or return "FOSUserBundle"; but you can't put both
}
I'm using FOSMessageBundle, and I thought i followed the instructions pretty well, but i cant seem to get the database to generate properly...
Heres my Message entity:
<?php
namespace Acme\Bundle\DemoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as JMS;
use FOS\MessageBundle\Entity\Message as BaseMessage;
use FOS\MessageBundle\Model\ParticipantInterface;
/**
* Message
*
* #ORM\Entity()
* #JMS\ExclusionPolicy("All")
*/
class Message extends BaseMessage implements EntityInterface
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
* #JMS\Groups({"list", "default"})
* #JMS\Expose()
*/
protected $id;
/**
* #var Thread
*
* #ORM\ManyToOne(targetEntity="Thread", inversedBy="messages", cascade={"persist"})
* #ORM\JoinColumn(name="thread_id")
* #JMS\Groups({"default"})
*/
protected $thread;
/**
* #ORM\ManyToOne(targetEntity="User")
* #var ParticipantInterface
*/
protected $sender;
/**
* #ORM\OneToMany(targetEntity="MessageMetadata", mappedBy="message", cascade={"all"})
* #var MessageMetadata
*/
protected $metadata;
}
And my config.yml
fos_message:
db_driver: orm
thread_class: Acme\Bundle\DemoBundle\Entity\Thread
message_class: Acme\Bundle\DemoBundle\Entity\Message
The issue is, my table ends up with only id, thread_id, and sender_id. Its missing the rest of the fields.
What am i missing!
check if all classes are correcly mapped :
php app/console doctrine:mapping:info
if not you have to MessageMetadata to the config file
message_class: Acme\Bundle\DemoBundle\Entity\Message
I'm not sure but in your case it seems like you have two different configurations for this entity - your annotations and xml from FOSCommentBundle
Please change your configuration to XML format, like this https://github.com/FriendsOfSymfony/FOSMessageBundle/blob/master/Resources/config/doctrine/Message.orm.xml and check again.
regards,
Merk, one of the contributors to the project pointed me at setting auto_mapping to true under the entity manager.
Once i set this, it solved my issue!
For me the auto_mapping did not work, I got the message
Unrecognized option "auto_mapping" under "doctrine.orm"
I solved the issue by adding the FOSMessageBundle like this:
orm:
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: default
entity_managers:
default:
naming_strategy: doctrine.orm.naming_strategy.underscore
connection: default
second_level_cache:
enabled: true
mappings:
AppBundle: ~
UserBundle: ~
FOSMessageBundle: ~
I'm new Symfony2 user and I need help!
I have two Bundles with entities:
// My\FooBundle\Entity\Foo.php
namespace My\FooBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(name="foo")
* #ORM\Entity
*/
class Foo
{
/*...*/
/**
* #ORM\OneToOne(targetEntity="My\BarBundle\Entity\Bar")
*/
private $bar;
}
And in another bundle:
// My\BarBundle\Entity\Bar.php
namespace My\BarBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(name="bar")
* #ORM\Entity
*/
class Bar
{
/*...*/
/**
* #ORM\Column(name="name", nullable=false)
*/
private $name;
}
And my config.yml:
doctrine:
dbal:
default_connection: foo
connections:
foo:
dbname: "foo"
bar:
dbname: "bar"
orm:
entity_managers:
foo:
connection: foo
mappings:
MyFooBundle: ~
MyBarBundle: ~
bar:
connection: bar
mappings:
MyBarBundle: ~
And SF creates Bar in Foo database.
Q: How do I create a relation between two connections in this situation?
Remove MyBarBundle bundle from foo connection.
Add database name to bar entity
// My\BarBundle\Entity\Bar.php
namespace My\BarBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(name="bar.bar")
* #ORM\Entity
*/
class Bar
{
/*...*/
/**
* #ORM\Column(name="name", nullable=false)
*/
private $name;
}
And following strings to config.yml:
doctrine:
dbal:
default_connection: foo
connections:
foo:
dbname: "foo"
bar:
dbname: "bar"
orm:
entity_managers:
foo:
connection: foo
mappings:
MyFooBundle: ~
MyBarBundle:
type: "annotation"
dir: ..\..\My\BarBundle\Entity
bar:
connection: bar
mappings:
MyBarBundle:
type: "annotation"
dir: ..\..\My\BarBundle\Entity
I'm very new to Symfony 2.0 and doctrine. I have state and customer entity in different bundle. I just want to add relation between state and customer. I'm coded state and customer entities. Here is the my code:
/**
* #orm:Entity
*/
class Customer
{
/**
* #orm:Id
* #orm:Column(type="integer")
* #orm:GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #OneToOne(targetEntity="State")
* #JoinColumn(name="state_id", referencedColumnName="id")
*/
protected $state;
}
/**
* #orm:Entity
*/
class State
{
/**
* #orm:Id
* #orm:Column(type="integer")
* #orm:GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #orm:Column(type="string", length="50")
*/
protected $name;
}
And my config file:
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
dbname: %database_name%
user: %database_user%
password: %database_password%
orm:
auto_generate_proxy_classes: %kernel.debug%
mappings:
FogCustomerBundle: { type: annotation, dir: Entity/ }
FogMainBundle: { type: annotation, dir: Entity/ }
So my problem is when I generate schema using php app/console doctrine:schema:create command tables are generated. But relationship doesn't generated /state column doesn't generead in customer table/. Why? I don't have any idea? I'll very happy for every advise and post.
You can run into that problem if you're closely following examples from the Doctrine2 documentation, because Symfony2 places all the Doctrine2 annotations into the orm namespace, which you seem to be missing on your OneToOne and JoinColumn annotations. Your code for the $state property should look like this:
/**
* #orm:OneToOne(targetEntity="State")
* #orm:JoinColumn(name="state_id", referencedColumnName="id")
*/
protected $state;
EDIT: With changes introduced in Symfony2 beta2, annotations have changed a little. Annotations need to be imported before they are used; importing Doctrine looks like this:
use Doctrine\ORM\Mapping as ORM;
Then the new usage looks like this:
/**
* #ORM\OneToOne(targetEntity="State")
* #ORM\JoinColumn(name="state_id", referencedColumnName="id")
*/
protected $state;
There is some discussion of further changes to the annotation system; if these changes are rolled out, I'll be back with another edit.