Deleting stubbed foreign key only works through model.delete()
See original GitHub issueDBFlow Version: 4.0.4 Issue Kind (Bug, Question, Feature): Bug
Description: Currently, after setting up everything correctly,
- Enabling foreign key constraints
@Database(
name = OrgaDatabase.NAME,
version = OrgaDatabase.VERSION,
insertConflict = ConflictAction.IGNORE,
updateConflict= ConflictAction.REPLACE,
foreignKeyConstraintsEnforced = true
)
- Defining all correct annotations to the foreign key in model
@ForeignKey(
stubbedRelationship = true,
saveForeignKeyModel = true,
deleteForeignKeyModel = true,
onDelete = ForeignKeyAction.CASCADE)
@SerializedName("user_detail")
private UserDetail userDetail;
- Defining a primary key in foreign model
@Table(database = OrgaDatabase.class, allFields = true)
public class UserDetail extends BaseModel {
@PrimaryKey(autoincrement = true)
private int id;
private String contact;
private String twitter;
@SerializedName("firstname")
private String firstName;
private String avatar;
private String facebook;
@SerializedName("lastname")
private String lastName;
private String details;
}
I’m only able to delete the foreign key model from database by calling user.delete()
Both of these methods don’t work ->
Delete.table(User.class);
SQLite.delete().from(User.class).execute()
I have to resort to this to actually delete the user and userdetails
Click to see code
User user = new User();
UserDetail userDetail = new UserDetail();
user.setUserDetail(userDetail);
user.setId(2);
user.setEmail("jamal.areeb@gmail.com");
user.setLastAccessTime("lol");
user.setSignupTime("bawa");
userDetail.setFirstName("Areeb");
userDetail.setLastName("Jamal");
userDetail.setDetails("A B C D");
user.save();
databaseRepository.getAllItems(UserDetail.class).subscribe(user1 -> {
System.out.println("Detail : " + user1);
});
List<User> users = SQLite.select().from(User.class).queryList();
for (User user1 : users) {
user.delete();
}
databaseRepository.getAllItems(UserDetail.class).subscribe(user1 -> {
System.out.println("Detail : " + user1);
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Problem in Deleting Model Entries having ForeignKey ...
I tried implementing your problem on my localmachine. Django causes this error because of foreign key constraint.
Read more >Django ORM | Foreign Key Deletion Constraints - YouTube
In this tutorial we review the 7 behaviours that we can define for when the referenced object is deleted in a foreign key...
Read more >Cascade Delete - EF Core | Microsoft Learn
Configuring cascading behaviors triggered when an entity is deleted or severed from its principal/parent.
Read more >SQL Server: Foreign Keys with set null on delete
A foreign key with "set null on delete" means that if a record in the parent table is deleted, then the corresponding records...
Read more >CHANGES — oslo.versionedobjects 1.18.0 documentation
Update README.rst; Remove serialize_args(), per the work items ... Remove instance Foreign Key in volumes table, replace with instance_uuid; Remove old ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
you can use
FlowManager.getModelAdapter(User.class).deleteAll(models)
OK 👍