question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using Related field under different name

See original GitHub issue

I want to use Related field for many to many relations in my schemas but under different name than real property name, but there is problems on serialization step even if using attribute argument pointing to wanted property because Marshmallow trying to access same property but pick it from related model.

Any guides how to use Related field under different name than property name?

Pseudocode example:

class Article(Base):
    id = Column(UUID,
                server_default=text('gen_random_uuid()'),
                primary_key=True)
    name = Column(String(256))
    pictures = relationship('File', secondary=article_to_picture)

class ArticleSchema(ModelSchema):
    class Meta:
        model = Article
    pictures_ids = fields.List(Relation(attribute='pictures'), attribute='pictures'))
    pictures = fields.Nested('FileSchema',
                             attribute='pictures',
                             many=True,
                             only=['id', 'name', 'url'],
                             dump_only=True)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sloriacommented, Nov 3, 2018

@AbdealiJK Ah, ok. As long as you have dump_only=True or load_only=True set on either of the fields, then you will not run into any issues.

1reaction
zeziccommented, Nov 3, 2018

Thank you, @sloria and @AbdealiJK! It was long time ago, I will review my code soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Querying using related field names - django - Stack Overflow
I'm wondering how to do this given the fact that one model has to fields with foreign keys to the same model. class...
Read more >
Similar field name on different objects : not easy when used in ...
We have some fields duplicated on different objects (used in workflow & field updates & email alerts). This is all working fine.
Read more >
Guidelines for naming fields, controls, and objects
When you name a field, control, or object, it's a good idea to make sure the name doesn't duplicate the name of a...
Read more >
Define fields in tables—ArcGIS Pro | Documentation
Field names in the same table must be unique; for instance, you can't have two fields with the name ObjectID.
Read more >
Editing field names and descriptions - Amazon QuickSight
You can change any field name and description from what is provided by the data source. If you change the name of a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found