laravel-mongodb icon indicating copy to clipboard operation
laravel-mongodb copied to clipboard

latestOfMany() doesnt work

Open masterbater opened this issue 11 months ago • 2 comments

  • Laravel-mongodb Version: 5.1
  • PHP Version: 8.3
  • Database Driver & Version:

Description:

Steps to reproduce

doesnt work it doesnt return the latest value,

 public function latestTwilioMessage(): HasOne
    {
        return $this->hasOne(TwilioMessageHistory::class)->latestOfMany('date_sent');
    }
checking latestOfMany method it uses 
    public function latestOfMany($column = 'id', $relation = null)
    {
        return $this->ofMany((new Collection(Arr::wrap($column)))->mapWithKeys(function ($column) {
            return [$column => 'MAX'];
        })->all(), 'MAX', $relation);
    }

For now I use this, seems to work ok.

 public function latestTwilioMessage(): HasOne
    {
        return $this->hasOne(TwilioMessageHistory::class)->latest('date_sent');
    }

masterbater avatar Dec 22 '24 20:12 masterbater

I'm looking at this issue. Tracked in Jira: PHPORM-281

GromNaN avatar Jan 23 '25 11:01 GromNaN

I've spent a lot of time looking into this, but I haven't found a solution. I'll leave it open, if anyone wants to look into it. In the meantime, there is a solution described in this issue.

GromNaN avatar Jan 28 '25 09:01 GromNaN