Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when getting relationships #65

Open
rainpoiss opened this issue Aug 25, 2017 · 4 comments
Open

Error when getting relationships #65

rainpoiss opened this issue Aug 25, 2017 · 4 comments
Labels

Comments

@rainpoiss
Copy link

/{ct}/{id}/{relatedtype} works only one way.
Example I have ct pages and ct categories
i choose relationship when creating new page.
it works when i make request /pages/1/categories
but when i try to use it the other way:
categories/1pages/
i get the error:

Uncaught Exception: StorageException .

StorageException in Relations.php line 205:
Unable to load collection values. Ensure that EntityManager is set on Bolt\Storage\Collection\Relations

@xiaohutai
Copy link
Owner

Have you explicitly defined both relationships in contenttypes.yml? As in, does the contenttype categories have a relation to pages (and vice versa)?

@rainpoiss
Copy link
Author

yes I have under categories:
relations:
pages:
multiple: true
label: Sisuleht
order: -id

under pages:

relations:
categories:
multiple: false
label: Kategooria
order: -id

I have a discovered when i delete relation under categories and add it there again, then it works...
But default it apperars under categories.

@rainpoiss
Copy link
Author

the following table structure


"id","from_contenttype","from_id","to_contenttype","to_id"
2,"sections",1,"pages",1
3,"pages",2,"sections",1
4,"pages",3,"sections",1

gives me this response in API

{
    "links": {
        "self": "http:\/\/localhost\/json\/sections\/1",
        "sections": {
            "href": "http:\/\/localhost\/json\/sections\/2\/sections",
            "meta": {
                "count": 1
            }
        },
        "pages": {
            "href": "http:\/\/localhost\/json\/sections\/3\/pages",
            "meta": {
                "count": 1
            }
        }
    },

@xiaohutai xiaohutai added the bug label Jul 30, 2018
@Raistlfiren
Copy link
Collaborator

Hi,
As of right now it seems as though Bolt is not getting the relationship properly, or I am using it incorrectly. The error lies with the code - https://github.com/xiaohutai/jsonapi/blob/master/src/Action/SingleAction.php#L49

When attempting to get related content, it calls the internal Bolt method getRelation() and only attempts to checks the to_contenttype. At this time there is no way to set bidirectional to true. This is the line in question - https://github.com/bolt/bolt/blob/c3ead6d48cc2431d72ae7f81947df7fa5fefa92b/src/Storage/Collection/Relations.php#L224

@rossriley - Are the Bolt internals functioning correctly, or is there a problem with the my code? getRelation($contentType)->count() is always returning 0 on inverse relationships. Shouldn't bi-drecirectional relationships always default to true since all Bolt relationships are supposed to be that? Here is what my relationship looks like in Bolt -
screen shot 2019-03-06 at 4 45 45 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants