func (s *StoragePostgres) checkOnlyRootTagging(tx *sql.Tx) error {
	// Get all root tags
	rootTagIDs := []int{}
	rows, err := tx.Query("SELECT id FROM tags WHERE parent_id IS NULL")
	if err != nil {
		return errors.Trace(err)
	}
	defer rows.Close()
	for rows.Next() {
		var cur int
		err := rows.Scan(&cur)
		if err != nil {
			return errors.Trace(err)
		}
		rootTagIDs = append(rootTagIDs, cur)
	}
	rows.Close()

	// For each of the root tags, make sure there's no taggables tagged only
	// with this one tag
	for _, rootTagID := range rootTagIDs {
		badIDs, err := s.getTaggablesTaggedWithOnlyOneTag(tx, rootTagID)
		if err != nil {
			return errors.Trace(err)
		}
		if len(badIDs) > 0 {
			return errors.Errorf(
				"some taggables (ids: %v) are tagged with root tag only (id: %d), this is illegal",
				badIDs, rootTagID,
			)
		}
	}

	return nil
}
// It's illegal for the taggable to be tagged with the root tag only,
// so checkOnlyRootTagging checks for these cases
It's illegal for the taggable to be tagged with the root tag only,
so checkOnlyRootTagging checks for these cases
// It ' s illegal for the taggable to be tagged with the root tag only // so checkOnlyRootTagging checks for these cases
func (s *StoragePostgres) checkOnlyRootTagging(tx *sql.Tx) error {
	rootTagIDs := []int{}
	rows, err := tx.Query("SELECT id FROM tags WHERE parent_id IS NULL")
	if err != nil {
		return errors.Trace(err)
	}
	defer rows.Close()
	for rows.Next() {
		var cur int
		err := rows.Scan(&cur)
		if err != nil {
			return errors.Trace(err)
		}
		rootTagIDs = append(rootTagIDs, cur)
	}
	rows.Close()
	for _, rootTagID := range rootTagIDs {
		badIDs, err := s.getTaggablesTaggedWithOnlyOneTag(tx, rootTagID)
		if err != nil {
			return errors.Trace(err)
		}
		if len(badIDs) > 0 {
			return errors.Errorf(
				"some taggables (ids: %v) are tagged with root tag only (id: %d), this is illegal",
				badIDs, rootTagID,
			)
		}
	}
	return nil
}
func ( s * StoragePostgres ) checkOnlyRootTagging ( tx * sql . Tx ) error { rootTagIDs := [ ] int { } rows , err := tx . Query ( " " ) if err != nil { return errors . Trace ( err ) } defer rows . Close ( ) for rows . Next ( ) { var cur int err := rows . Scan ( & cur ) if err != nil { return errors . Trace ( err ) } rootTagIDs = append ( rootTagIDs , cur ) } rows . Close ( ) for _ , rootTagID := range rootTagIDs { badIDs , err := s . getTaggablesTaggedWithOnlyOneTag ( tx , rootTagID ) if err != nil { return errors . Trace ( err ) } if len ( badIDs ) > 0 { return errors . Errorf ( " " , badIDs , rootTagID , ) } } return nil }
It's illegal for the taggable to be tagged with the root tag only,
so checkOnlyRootTagging checks for these cases
It ' s illegal for the taggable to be tagged with the root tag only so checkOnlyRootTagging checks for these cases
// Get all root tags // For each of the root tags, make sure there's no taggables tagged only // with this one tag