package com.litesuits.orm.model.cascade;

import com.litesuits.orm.db.annotation.Column;
import com.litesuits.orm.db.annotation.Mapping;
import com.litesuits.orm.db.annotation.Table;
import com.litesuits.orm.db.annotation.UniqueCombine;
import com.litesuits.orm.db.enums.Relation;
import com.litesuits.orm.model.Model;

/**
 * @author MaTianyu
 * @date 2015-03-24
 */
@Table("book")
public class Book extends Model {
    public static final String COL_AUTHOR = "author";
    public static final String COL_INDEX = "_index";
    /**
     * 和 author 联合唯一
     */
    @UniqueCombine(1)
    @Column(COL_INDEX)//避开SQL关键词
    private int index;

    /**
     * 和 index 联合唯一
     */
    @Column(COL_AUTHOR)
    @UniqueCombine(1)
    private String author;

    /**
     * 书和学生：多对一关系
     */
    @Mapping(Relation.ManyToOne)
    public Student student;

    public Book(String title) {
        super(title);
    }

    public int getIndex() {
        return index;
    }

    public Book setIndex(int index) {
        this.index = index;
        return this;
    }

    public String getAuthor() {
        return author;
    }

    public Book setAuthor(String author) {
        this.author = author;
        return this;
    }

    public Student getStudent() {
        return student;
    }

    public Book setStudent(Student student) {
        this.student = student;
        return this;
    }

    @Override public String toString() {
        return "Book{"
               + super.toString() +
               "index = " + index +
               ", author = " + author +
               ", student = "
               + (student == null ? "" : student.getName())
               + "} ";
    }
}

@@ -536,17 +536,47 @@
   * 
-%E5%92%8C author 
+UniqueCombine %E5%80%BC%E4%B8%BA1%EF%BC%8C%E5%92%8C UniqueCombine%E5%90%8C%E5%80%BC %E7%9A%84%E5%B1%9E%E6%80%A7
 %E8%81%94%E5%90%88%E5%94%AF%E4%B8%80
@@ -678,16 +678,33 @@
 %0A     * 
+UniqueCombine%E5%80%BC%E4%B8%BA1%EF%BC%8C
 %E5%92%8C index 
@@ -725,47 +725,47 @@
    @
-Column(COL_AUTHOR)%0A    @UniqueCombine(1
+UniqueCombine(1)%0A    @Column(COL_AUTHOR
 )%0A  

modify smaple