Problem serializing query result  to JSON
Yes, this is the intended behavior. That group by looks sketchy as hell since you're selecting columns that aren't included in the group by...granted, that probably works fine for SQLite and MySQL. Anyways!

`model_to_dict` probably isn't going to work correctly for what you're trying to do without some gymnastics. It's probably much easier to just do something like:

```python
accum = []
for user_obj in result:
    user_dict = model_to_dict(user_obj, recurse=False)
    user_dict['latest_event'] = model_to_dict(user_obj.event, recurse=False)
``` Thanks, the group_by clause had the wrong content (fixed now).

Does your solution still apply or is there some automated way now? Or is there a better way for the query so that there is an automated way? The solution I gave is probably the easiest way to achieve what you want. Events is a backref from the perspective of the user object, so peewee treats it as a list. Since you only need the one event per user, just use the approach I suggested. The given example works as expected. Thank you very much for your help. I think I just expected too much automatism after reading the manual. :)

Some minor stuff: I think you forgot to add the user_dict to the accum list in your example.
Following model:

```
class User(BaseModel):
    ...

class Event(BaseModel):
    ...
    user = ForeignKeyField(User, related_name='events')
```

I want to have the newest event for each user:
```
        result = (User
                 .select(User, Event)
                 .join(Event)
                 .group_by(Event.user_id)
                 .having(fn.MAX(Event.create_date))
                 .order_by(Event.create_date.desc())
                 )
```

and then serialize the result to JSON:
```
serialized = [model_to_dict(r, recurse=True, backrefs=True) for r in result]
```

unfortunately now ALL events are included in the serialized data (guess that's what backrefs does), not just the newest like in my query. Is this the intended behaviour? How can I only get the user/event I was selecting for in the query?

Thanks for your help.