()
| 144 | } |
| 145 | |
| 146 | func (m *Book) Insert() (err error) { |
| 147 | o := orm.NewOrm() |
| 148 | if _, err = o.Insert(m); err != nil { |
| 149 | return |
| 150 | } |
| 151 | |
| 152 | if m.Label != "" { |
| 153 | NewLabel().InsertOrUpdateMulti(m.Label) |
| 154 | } |
| 155 | |
| 156 | relationship := NewRelationship() |
| 157 | relationship.BookId = m.BookId |
| 158 | relationship.RoleId = 0 |
| 159 | relationship.MemberId = m.MemberId |
| 160 | |
| 161 | if err = relationship.Insert(); err != nil { |
| 162 | logs.Error("插入书籍与用户关联 => ", err) |
| 163 | return err |
| 164 | } |
| 165 | |
| 166 | document := NewDocument() |
| 167 | document.BookId = m.BookId |
| 168 | document.DocumentName = "空白文档" |
| 169 | document.Identify = "blank" |
| 170 | document.MemberId = m.MemberId |
| 171 | |
| 172 | var id int64 |
| 173 | if id, err = document.InsertOrUpdate(); err == nil { |
| 174 | var ds = DocumentStore{ |
| 175 | DocumentId: int(id), |
| 176 | Markdown: "[TOC]\n\r\n\r", //默认内容 |
| 177 | } |
| 178 | err = new(DocumentStore).InsertOrUpdate(ds) |
| 179 | } |
| 180 | return err |
| 181 | } |
| 182 | |
| 183 | func (m *Book) Find(id int, cols ...string) (book *Book, err error) { |
| 184 | if id <= 0 { |
no test coverage detected