Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mikeritter's avatar

Eloquent relationships with date field as key

Can we do a hasMany relationship based on a date field?

class Workout extends Eloquent{
    ...

    public function logs(){
        return $this->hasMany('Log','date','date');
    }

}

0 likes
6 replies
zoransa's avatar

You know what... I would not do it. Most probably you do not use some variable that is frozen like 'request time' and then save it to every single table... your requests take several milliseconds and also they are dependent on system time on mysql server so you never get the same time even if queries are very close to each other in the code.

mikeritter's avatar

These are date fields. I.e. "2015-03-11".

Still wouldn't work?

mikeritter's avatar

i did, but it isn't working. just didn't want to chase a rabbit trail.

mikeritter's avatar

@JarekTkaczyk , I worked it out. Just didn't want to waste time on something that wouldn't work.

I'm excited for this epiphany so I can:

  1. simplify my queries

  2. tie my business logic into the db model

Please or to participate in this conversation.