[#2029] enable any id aliased column in a view query to be detected as relation field
This commit is contained in:
		
							parent
							
								
									67ecebe935
								
							
						
					
					
						commit
						7a2360d785
					
				| 
						 | 
				
			
			@ -11,6 +11,8 @@
 | 
			
		|||
 | 
			
		||||
- Removed the `COALESCE` wrapping from some of the generated filter conditions to make better use of the indexes ([#1939](https://github.com/pocketbase/pocketbase/issues/1939)).
 | 
			
		||||
 | 
			
		||||
- Detect `id` aliased view columns as single `relation` fields ([#2029](https://github.com/pocketbase/pocketbase/discussions/2029)).
 | 
			
		||||
 | 
			
		||||
- Optimized single relation lookups.
 | 
			
		||||
 | 
			
		||||
- Normalized record values on `maxSelect` field option change (`select`, `file`, `relation`).
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -279,16 +279,13 @@ func (dao *Dao) parseQueryToFields(selectQuery string) (map[string]*queryField,
 | 
			
		|||
 | 
			
		||||
		var fieldName string
 | 
			
		||||
		var collection *models.Collection
 | 
			
		||||
		var isMainTableField bool
 | 
			
		||||
 | 
			
		||||
		if len(parts) == 2 {
 | 
			
		||||
			fieldName = parts[1]
 | 
			
		||||
			collection = collections[parts[0]]
 | 
			
		||||
			isMainTableField = parts[0] == mainTable.alias
 | 
			
		||||
		} else {
 | 
			
		||||
			fieldName = parts[0]
 | 
			
		||||
			collection = collections[mainTable.alias]
 | 
			
		||||
			isMainTableField = true
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// fallback to the default field if the found column is not from a collection schema
 | 
			
		||||
| 
						 | 
				
			
			@ -323,8 +320,8 @@ func (dao *Dao) parseQueryToFields(selectQuery string) (map[string]*queryField,
 | 
			
		|||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if fieldName == schema.FieldNameId && !isMainTableField {
 | 
			
		||||
			// convert to relation since it is a direct id reference to non-maintable collection
 | 
			
		||||
		if fieldName == schema.FieldNameId {
 | 
			
		||||
			// convert to relation since it is a direct id reference
 | 
			
		||||
			result[col.alias] = &queryField{
 | 
			
		||||
				field: &schema.SchemaField{
 | 
			
		||||
					Name: col.alias,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -399,7 +399,7 @@ func TestCreateViewSchema(t *testing.T) {
 | 
			
		|||
			`,
 | 
			
		||||
			false,
 | 
			
		||||
			map[string]string{
 | 
			
		||||
				"id2":           schema.FieldTypeJson,
 | 
			
		||||
				"id2":           schema.FieldTypeRelation,
 | 
			
		||||
				"text_alias":    schema.FieldTypeText,
 | 
			
		||||
				"url_alias":     schema.FieldTypeUrl,
 | 
			
		||||
				"bool_alias":    schema.FieldTypeBool,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue