Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load Related #1

Open
aledebs opened this issue Jan 20, 2015 · 2 comments
Open

Load Related #1

aledebs opened this issue Jan 20, 2015 · 2 comments
Assignees
Milestone

Comments

@aledebs
Copy link

aledebs commented Jan 20, 2015

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!

rmasters added a commit that referenced this issue Jan 20, 2015
@rmasters
Copy link
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

@aledebs
Copy link
Author

aledebs commented Jan 21, 2015

Great! Thanks for add.

@rmasters rmasters self-assigned this Jan 21, 2015
@rmasters rmasters added this to the Lazy loading milestone Jan 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants