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

One-to-many relationships are serialized with None value when eager-loaded #798

Open
federicoparroni opened this issue Oct 4, 2022 · 1 comment
Labels
bug An existing feature is not working as intended

Comments

@federicoparroni
Copy link
Contributor

federicoparroni commented Oct 4, 2022

Describe the bug
When one-to-many relationships is eager-loaded (using the _with function) from a record, the serialized value for the related field is set as None.

To Reproduce

class Category(Model):
    __hidden__ = [
        'id',
        'created_at',
        'updated_at'
    ]

    @belongs_to('website_id', 'id')
    def websites(self):
        return Website

class Website(Model, SoftDeletesMixin):
    __appends__ = [
        'categories',
    ]

    @has_many('id', 'website_id')
    def categories(self):
       return Category

data = Website.with_('categories').first().serialize()
print(data)    # data["categories"] is None

Expected behavior
The serialized value for the related field should be set as an empty array.

Desktop (please complete the following information):

  • OS: Linux
  • Version: Ubuntu 22.04

What database are you using?

  • Type: [MySQL]
  • Version [14.14 Distrib 5.7.30, for Linux (x86_64) using EditLine wrapper]
  • Masonite ORM [2.18.5]
@federicoparroni federicoparroni added the bug An existing feature is not working as intended label Oct 4, 2022
@Chiu-Kevin-bah
Copy link

Chiu-Kevin-bah commented Apr 14, 2023

Also take out the appends. That’s for custom attributes. You have the with() already

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

No branches or pull requests

2 participants