Skip to content

Limit many to many relationships. #284

@lsfratel

Description

@lsfratel

Hello guys, I'm trying to limit a many to many relationship with the following code:

$latest = Manga::including(['chapters' => function($q) {
	$q->descending('number');
	$q->limit(1);
}])->limit(24)->all();

query result:

[
    ...
    {
        ...
        updated_at: "2020-10-29 21:41:13",
        chapters: [ ] //empty
    },
    {
        ...
        updated_at: "2020-10-29 21:41:39",
        chapters: [
        {
            id: "1528",
            number: "398",
            name: "",
            manga_id: "5",
            created_at: "2020-10-29 21:42:50",
            updated_at: "2020-10-29 21:42:50"
        }
    }
]

but it only work for 1 manga record with id 5, I don't know whats wrong, can u guys tell me?

P.S: sorry bad english.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions