mirror of https://github.com/velour/catbase.git
fact: fix reverse detection
This commit is contained in:
parent
c6709ae521
commit
c708aec4a4
|
@ -67,15 +67,17 @@ func findAlias(db *sqlx.DB, fact string) (bool, *factoid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *alias) save(db *sqlx.DB) error {
|
func (a *alias) save(db *sqlx.DB) error {
|
||||||
ok, _ := findAlias(db, a.Fact)
|
q := `select * from factoid_alias where fact=?`
|
||||||
if ok {
|
var offender alias
|
||||||
|
err := db.Get(&offender, q, a.Next)
|
||||||
|
if err == nil {
|
||||||
return fmt.Errorf("DANGER: an opposite alias already exists")
|
return fmt.Errorf("DANGER: an opposite alias already exists")
|
||||||
}
|
}
|
||||||
_, err := a.resolve(db)
|
_, err = a.resolve(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("there is no fact at that destination")
|
return fmt.Errorf("there is no fact at that destination")
|
||||||
}
|
}
|
||||||
q := `insert or replace into factoid_alias (fact, next) values (?, ?)`
|
q = `insert or replace into factoid_alias (fact, next) values (?, ?)`
|
||||||
_, err = db.Exec(q, a.Fact, a.Next)
|
_, err = db.Exec(q, a.Fact, a.Next)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue