Api-platform filter annotation for Many To Many
I've follow the implementation of filters with annotation to load only the sources concern for one user. Very usefull, work properly.
https://api-platform.com/docs/core/filters/#using-doctrine-filters
BUT : I want to do the same in my entity with an ManyToMany relationship and not ManyToOne like this :
<?php
namespace AppEntity;
use ApiPlatformCoreAnnotationApiResource;
use ApiPlatformCoreAnnotationApiSubresource;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorConstraints as Assert;
use DoctrineCommonCollectionsArrayCollection;
use AppAnnotationUserAware;
/**
*
* @ApiResource(routePrefix="/api")
* @ORMEntity
* @ORMTable(name="albums")
* @UserAware(userFieldName="user_owner")
* @UserAware(userFieldName="album_access_user")
*/
class Album
{
//...
/**
* @ORMManyToOne(targetEntity="User")
* @ORMJoinColumn(nullable=false, name="user_owner", referencedColumnName="id")
*/
public $userOwner;
/**
* @ORMManyToMany(targetEntity="User", inversedBy="albums")
* @ORMJoinTable(name="album_access")
* @ORMJoinTable(
* name="album_access",
* joinColumns={
* @ORMJoinColumn(name="album_access_album", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORMJoinColumn(name="album_access_user", referencedColumnName="id")
* }
* )
*/
private $accesses;
//...
}
AS there is a JoinTable now and not just a JoinColum, i have to adapt the UserFilterConfigurator.php Event but i've no idea how to do that to give him the table and not juste the column...
Here is the logic error i get because i ask for the Entity Table and not the Join Table for now :
An exception occurred while executing 'SELECT DISTINCT o0_.id AS id_0, o0_.id AS id_1 FROM albums o0_ WHERE (o0_.album_access_user = '4') ORDER BY o0_.id ASC LIMIT 30':nnSQLSTATE[42703]: Undefined column: 7 ERROR: column o0_.album_access_user does not existnLINE 1: ...id_0, o0_.id AS id_1 FROM albums o0_ WHERE (o0_...
How can I get that for ManyToMany <=> how can i pass the good (join)table + (join) column ??
php symfony symfony4 api-platform.com
add a comment |
I've follow the implementation of filters with annotation to load only the sources concern for one user. Very usefull, work properly.
https://api-platform.com/docs/core/filters/#using-doctrine-filters
BUT : I want to do the same in my entity with an ManyToMany relationship and not ManyToOne like this :
<?php
namespace AppEntity;
use ApiPlatformCoreAnnotationApiResource;
use ApiPlatformCoreAnnotationApiSubresource;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorConstraints as Assert;
use DoctrineCommonCollectionsArrayCollection;
use AppAnnotationUserAware;
/**
*
* @ApiResource(routePrefix="/api")
* @ORMEntity
* @ORMTable(name="albums")
* @UserAware(userFieldName="user_owner")
* @UserAware(userFieldName="album_access_user")
*/
class Album
{
//...
/**
* @ORMManyToOne(targetEntity="User")
* @ORMJoinColumn(nullable=false, name="user_owner", referencedColumnName="id")
*/
public $userOwner;
/**
* @ORMManyToMany(targetEntity="User", inversedBy="albums")
* @ORMJoinTable(name="album_access")
* @ORMJoinTable(
* name="album_access",
* joinColumns={
* @ORMJoinColumn(name="album_access_album", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORMJoinColumn(name="album_access_user", referencedColumnName="id")
* }
* )
*/
private $accesses;
//...
}
AS there is a JoinTable now and not just a JoinColum, i have to adapt the UserFilterConfigurator.php Event but i've no idea how to do that to give him the table and not juste the column...
Here is the logic error i get because i ask for the Entity Table and not the Join Table for now :
An exception occurred while executing 'SELECT DISTINCT o0_.id AS id_0, o0_.id AS id_1 FROM albums o0_ WHERE (o0_.album_access_user = '4') ORDER BY o0_.id ASC LIMIT 30':nnSQLSTATE[42703]: Undefined column: 7 ERROR: column o0_.album_access_user does not existnLINE 1: ...id_0, o0_.id AS id_1 FROM albums o0_ WHERE (o0_...
How can I get that for ManyToMany <=> how can i pass the good (join)table + (join) column ??
php symfony symfony4 api-platform.com
add a comment |
I've follow the implementation of filters with annotation to load only the sources concern for one user. Very usefull, work properly.
https://api-platform.com/docs/core/filters/#using-doctrine-filters
BUT : I want to do the same in my entity with an ManyToMany relationship and not ManyToOne like this :
<?php
namespace AppEntity;
use ApiPlatformCoreAnnotationApiResource;
use ApiPlatformCoreAnnotationApiSubresource;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorConstraints as Assert;
use DoctrineCommonCollectionsArrayCollection;
use AppAnnotationUserAware;
/**
*
* @ApiResource(routePrefix="/api")
* @ORMEntity
* @ORMTable(name="albums")
* @UserAware(userFieldName="user_owner")
* @UserAware(userFieldName="album_access_user")
*/
class Album
{
//...
/**
* @ORMManyToOne(targetEntity="User")
* @ORMJoinColumn(nullable=false, name="user_owner", referencedColumnName="id")
*/
public $userOwner;
/**
* @ORMManyToMany(targetEntity="User", inversedBy="albums")
* @ORMJoinTable(name="album_access")
* @ORMJoinTable(
* name="album_access",
* joinColumns={
* @ORMJoinColumn(name="album_access_album", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORMJoinColumn(name="album_access_user", referencedColumnName="id")
* }
* )
*/
private $accesses;
//...
}
AS there is a JoinTable now and not just a JoinColum, i have to adapt the UserFilterConfigurator.php Event but i've no idea how to do that to give him the table and not juste the column...
Here is the logic error i get because i ask for the Entity Table and not the Join Table for now :
An exception occurred while executing 'SELECT DISTINCT o0_.id AS id_0, o0_.id AS id_1 FROM albums o0_ WHERE (o0_.album_access_user = '4') ORDER BY o0_.id ASC LIMIT 30':nnSQLSTATE[42703]: Undefined column: 7 ERROR: column o0_.album_access_user does not existnLINE 1: ...id_0, o0_.id AS id_1 FROM albums o0_ WHERE (o0_...
How can I get that for ManyToMany <=> how can i pass the good (join)table + (join) column ??
php symfony symfony4 api-platform.com
I've follow the implementation of filters with annotation to load only the sources concern for one user. Very usefull, work properly.
https://api-platform.com/docs/core/filters/#using-doctrine-filters
BUT : I want to do the same in my entity with an ManyToMany relationship and not ManyToOne like this :
<?php
namespace AppEntity;
use ApiPlatformCoreAnnotationApiResource;
use ApiPlatformCoreAnnotationApiSubresource;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorConstraints as Assert;
use DoctrineCommonCollectionsArrayCollection;
use AppAnnotationUserAware;
/**
*
* @ApiResource(routePrefix="/api")
* @ORMEntity
* @ORMTable(name="albums")
* @UserAware(userFieldName="user_owner")
* @UserAware(userFieldName="album_access_user")
*/
class Album
{
//...
/**
* @ORMManyToOne(targetEntity="User")
* @ORMJoinColumn(nullable=false, name="user_owner", referencedColumnName="id")
*/
public $userOwner;
/**
* @ORMManyToMany(targetEntity="User", inversedBy="albums")
* @ORMJoinTable(name="album_access")
* @ORMJoinTable(
* name="album_access",
* joinColumns={
* @ORMJoinColumn(name="album_access_album", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORMJoinColumn(name="album_access_user", referencedColumnName="id")
* }
* )
*/
private $accesses;
//...
}
AS there is a JoinTable now and not just a JoinColum, i have to adapt the UserFilterConfigurator.php Event but i've no idea how to do that to give him the table and not juste the column...
Here is the logic error i get because i ask for the Entity Table and not the Join Table for now :
An exception occurred while executing 'SELECT DISTINCT o0_.id AS id_0, o0_.id AS id_1 FROM albums o0_ WHERE (o0_.album_access_user = '4') ORDER BY o0_.id ASC LIMIT 30':nnSQLSTATE[42703]: Undefined column: 7 ERROR: column o0_.album_access_user does not existnLINE 1: ...id_0, o0_.id AS id_1 FROM albums o0_ WHERE (o0_...
How can I get that for ManyToMany <=> how can i pass the good (join)table + (join) column ??
php symfony symfony4 api-platform.com
php symfony symfony4 api-platform.com
asked Nov 23 '18 at 19:35
mBbkrmBbkr
479
479
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452131%2fapi-platform-filter-annotation-for-many-to-many%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452131%2fapi-platform-filter-annotation-for-many-to-many%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown