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.

One To Many Relationship documentation insufficient

See original GitHub issue

DBFlow Version: 4.2.4

One To Many Relationship documentation insufficient: Missing Ant class in example and explanation on how to save models.

Please add the Ant class to make the One To Many example in the docs complete. It’s essential to get One To Many relationship working.

Since ModelContainers have been dropped, what do we need do in the Ant class instead of associating the former use of the ForeignKeyContainer?

Marco got me on the right track with his post but he ended up overwriting the Queen.save() in which he “associates” Ants with the Queen. Is it by design that you have to set this connection manually before save() or is it a bug?

I ended up with the following Ant class which seems to work. But is this correct?

@Table(database = ColonyDatabase.class)
public class Ant extends BaseModel {

  @PrimaryKey(autoincrement = true)
  long id;

  @Column
  String name;

  @ForeignKey(stubbedRelationship = true)
  Queen queen;

  // need to call this for all ants before saving the queen
  public void setQueen(Queen q) {
    queen = q;
  }
}

Thank you very much if you could clarify this.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
shuxinhuangcommented, Feb 3, 2018

i face the same issue , need help

0reactions
agrosnercommented, Oct 26, 2018

you can shortcut a load() if you want to associate a new queen with Ant by setting the queen object, then saving both Ant and Queen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL relationships - Fauna Documentation
A one-to-many relationship has high cardinality at only one side of the relationship. It is represented in the GraphQL schema by two types...
Read more >
Create, edit or delete a relationship - Microsoft Support
To create a one-to-many relationship The field on the one side (typically the primary key) of the relationship must have a unique index....
Read more >
Many-to-Many relationship that is different in both directions
I've been browsing answers here as well as books on database structure, but I suspect my lack of success finding the answer is...
Read more >
Relationships | Directus Docs
In an M2O relationship, multiple items from the parent collection ... An M2O relationship requires just one column within the parent table.
Read more >
Data Relationships in MongoDB – A quick guide
The document reference model can also be used to create a one-to-many relationship. We keep the documents separate in this model, but one ......
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