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

CASCADE Action onDelete #33

Closed
iKiKi opened this issue Jan 24, 2013 · 3 comments
Closed

CASCADE Action onDelete #33

iKiKi opened this issue Jan 24, 2013 · 3 comments

Comments

@iKiKi
Copy link

iKiKi commented Jan 24, 2013

Hi,

Lets take your example with Category and Item.

Category
@table(name = "Categories")
public class Category extends Model {

@Column(name = "Name", notNull = true, unique = true)
public String name;

public List<Item> items() {
    return getMany(Item.class, "Category");
}

public Category() {
    super();
}

public Category(String name) {
    super();
    this.name = name;
}

@Override
public String toString() {
    return new String("[" + Category.class.getName() + "] " 
            + "Name = " + name);
}

}

Item

@table(name = "Items")
public class Item extends Model {

@Column(name = "Name", notNull = true, unique = true)
public String name;

@Column(name = "Category", onDelete = ForeignKeyAction.CASCADE)
public Category category;

public Item() {
    super();
}

public Item(String name, Category category) {
    super();
    this.name = name;
    this.category = category;
}

@Override
public String toString() {
    return new String("[" + Item.class.getName() + "] " 
            + "Name = " + name + " | "
            + "Category = " + category);
}

}

After saving one Category data with many items, when I delete the inserted Category, the items remain in database. Is the CASCADE Action upon onDelete is working ? How to establish properly ForeignKeyActions ?

Thanks.

@vonloxley
Copy link
Contributor

Please see #32.

Could you merge https://github.com/vonloxley/ActiveAndroid/tree/reference_correct_table and try again?

@iKiKi
Copy link
Author

iKiKi commented Jan 24, 2013

I confirm DELETE ON CASCADE is now working with your #32.

@vonloxley
Copy link
Contributor

🎉

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

No branches or pull requests

3 participants