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

each table has only one Primary Key #22

Closed
Jayin opened this issue Jun 12, 2014 · 2 comments
Closed

each table has only one Primary Key #22

Jayin opened this issue Jun 12, 2014 · 2 comments

Comments

@Jayin
Copy link
Owner

Jayin commented Jun 12, 2014

bug like:

class Student extends Human {
    @PrimaryKey
    long id;

    int age;

    String name;

    List<Integer> friendid;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Integer> getFriendid() {
        return friendid;
    }

    public void setFriendid(List<Integer> friendid) {
        this.friendid = friendid;
    }

}

class Human extends Model {

    int height;

    int wight;

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getWight() {
        return wight;
    }

    public void setWight(int wight) {
        this.wight = wight;
    }

}

the sql below is incorrect

Create Table Student (name TEXT ,id INTEGER Primary Key AUTOINCREMENT,age INTEGER ,height INTEGER ,wight INTEGER ,__id INTEGER Primary Key AUTOINCREMENT)

typically,we are support to follow the user ---- remove the __id

@Jayin Jayin added bug labels Jun 12, 2014
Jayin added a commit that referenced this issue Jun 12, 2014
@Jayin
Copy link
Owner Author

Jayin commented Jun 13, 2014

Solution 1

firstly,we should controll the user action:
If the @PrimaryKey keeps opening,it may cause some confuse to some users who not very fimiliar to database :we can define one more Primary Key in one table.

so,I will remove it.

1.default @table(name="tablename",id="__id")

  • id means the PRIMARY KEY AUTOINCREMENT
  • motify the id to custom you primar key

2.When saving and delete the model,take care of the id

Solution 2

Solution 1 looks nice,but it's hard to code.Every time you save or delete,you have to figure out the where the id is.

to be lazy is:
Not able to give a right to user to motify the id

@Jayin Jayin changed the title every table has only one Primary Key each table has only one Primary Key Jun 13, 2014
@Jayin Jayin closed this as completed in 8613c07 Jun 20, 2014
@Jayin
Copy link
Owner Author

Jayin commented Jun 22, 2014

use @unique instead of @PrimaryKey

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

No branches or pull requests

1 participant