add artificial key for shopping_event_groceries
This commit is contained in:
parent
b81379432b
commit
8b2e4408fc
@ -10,8 +10,9 @@ Base = declarative_base()
|
||||
shopping_event_groceries = Table(
|
||||
'shopping_event_groceries',
|
||||
Base.metadata,
|
||||
Column('shopping_event_id', Integer, ForeignKey('shopping_events.id'), primary_key=True),
|
||||
Column('grocery_id', Integer, ForeignKey('groceries.id'), primary_key=True),
|
||||
Column('id', Integer, primary_key=True, autoincrement=True), # Artificial primary key
|
||||
Column('shopping_event_id', Integer, ForeignKey('shopping_events.id'), nullable=False),
|
||||
Column('grocery_id', Integer, ForeignKey('groceries.id'), nullable=False),
|
||||
Column('amount', Float, nullable=False), # Amount of this grocery bought in this event
|
||||
Column('price', Float, nullable=False) # Price of this grocery at the time of this shopping event
|
||||
)
|
||||
|
||||
@ -158,7 +158,10 @@ const ShoppingEventForm: React.FC = () => {
|
||||
|
||||
const getGroceryName = (id: number) => {
|
||||
const grocery = groceries.find(g => g.id === id);
|
||||
return grocery ? grocery.name : 'Unknown';
|
||||
if (!grocery) return 'Unknown';
|
||||
|
||||
const weightInfo = grocery.weight ? `${grocery.weight}${grocery.weight_unit}` : grocery.weight_unit;
|
||||
return `${grocery.name} ${weightInfo}`;
|
||||
};
|
||||
|
||||
if (loadingEvent) {
|
||||
@ -250,7 +253,7 @@ const ShoppingEventForm: React.FC = () => {
|
||||
<option value={0}>Select a grocery</option>
|
||||
{groceries.map(grocery => (
|
||||
<option key={grocery.id} value={grocery.id}>
|
||||
{grocery.name} ({grocery.category})
|
||||
{grocery.name} ({grocery.category}) {grocery.weight ? `${grocery.weight}${grocery.weight_unit}` : grocery.weight_unit}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user