Skip to content

Load Related #1

Open
Open

Description

@aledebs

Hello,
from you example:

foreach ($vehicles as $v) {
        echo sprintf("%s - %s\n", $v->name, $v->url);
        foreach ( $v->films as $film) {
                       // code?
            echo $film->title;
        }
    }

Film title on right is not populated. What's the best manner to fill object by $film->url ?
My idea is separate id from url and use it in FilmEndpoint get method. Is there another clean way?

Thanks for you work!

Activity

  1. rmasters commented on Jan 20, 2015

    @rmasters
    Owner

    Hi!

    Yeah, so I wanted to do an invisible lazy-load here - where you access $v->films[0] and it goes away and gets the full Film object for you. It's a bit fiddly with JsonMapper so I'll have a think about the best way to do that.

    In the meantime, I've added a method in v0.2.0 that allows you to get a resource by it's URI:

    $film = $swapi->getFromUri($film->uri);

    Cheers

  2. aledebs commented on Jan 21, 2015

    @aledebs
    Author

    Great! Thanks for add.

  3. self-assigned this
    on Jan 21, 2015
  4. added this to the Lazy loading milestone on Jan 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions