DatabaseView join query field naming convention #688
-
Extending this closed issue about the join query (#213). Please let me know if I should ask in there instead. I have question regarding the field / property naming convention. Let's say I set my table name on my entities to be Or do I need to alias them first? And what about the other properties? import 'package:floor/floor.dart';
@DatabaseView(
'SELECT'
' categories.id, categories.name, categories.label_color,'
' categories.created_at, categories.updated_at, menus.id,'
' menus.name, menus.price, menus.created_at, menus.updated_at '
'FROM menus'
'INNER JOIN categories ON categories.id = menus.category_id',
)
class CategoryMenu {
late int menusId; // Should this be [menuId] or [menusId] ?
late int categoriesId; // Should this be [categoryId] or [categoriesId] ?
// Should the rest be like this?
late String menusName;
late String categoriesName;
// Or like this?
late String menuName;
late String categoryName;
// if I want to use [menuId] instead of [menusId], should I make an alias on
// my query for each field?
// Like.. "SELECT menus.id AS menuId" ?
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@pratamatama I think we should follow the Dart language naming convention anyway. This means avoid using the possessive forms in naming. import 'package:floor/floor.dart';
@DatabaseView(
'SELECT'
' categories.id, categories.name, categories.label_color,'
' categories.created_at, categories.updated_at, menus.id,'
' menus.name, menus.price, menus.created_at, menus.updated_at '
'FROM menus'
'INNER JOIN categories ON categories.id = menus.category_id',
)
class CategoryMenu {
late int menuId;
late int categoryId;
late String menuName;
late String categoryName;
}
I think using aliases is better if some expression occurs multiple times. Don't see any reason to use it here 🤷♂️ |
Beta Was this translation helpful? Give feedback.
@pratamatama I think we should follow the Dart language naming convention anyway. This means avoid using the possessive forms in naming.
So in your case will be correct: