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

[NFR] Relation chain #12552

Closed
grzegorz-pierzakowski opened this issue Jan 16, 2017 · 8 comments
Closed

[NFR] Relation chain #12552

grzegorz-pierzakowski opened this issue Jan 16, 2017 · 8 comments
Labels
stale Stale issue - automatically closed

Comments

@grzegorz-pierzakowski
Copy link

grzegorz-pierzakowski commented Jan 16, 2017

Expected:
I whsh to define a relation with multiple joins as below:

$this->hasMany('id', Car::class, 'my_class_id', [
    'with' => 'tires'
]);

where tires i a oneToMany ralation alias on Car to Tire class I have already the 'tires' relation defined in the Car.

For now it's not working that way.

I am trying to get related modal data with one sql query and want the object + appropriate relations to be build then.

@Jurigag
Copy link
Contributor

Jurigag commented Jan 16, 2017

? Just use query builder:

$result = $modelsManager->createBuilder()
    ->columns('Salon.*, Car.*, Tires.*')
    ->from('Salon')
    ->leftJoin('Car')
    ->leftJoin('Tires')
    ->getQuery()
    ->execute();

You will get complex resultset with each row having Salon model, Car resultset and Tires resultset(or car array/tires array, i dont remember exactly).

Eager loading/deep relations/relation chain or however other you want to call it is bad and won't be implemented in phalcon. check #1117 especially @andresgutierrez comments

@grigoriy-ivanov
Copy link

grigoriy-ivanov commented Jan 16, 2017

@Jurigag. Eager loading very helps in the some cases. In your solution, you cannot get a model and it relationships like that:

  • Model
    • RelatedModel

@Jurigag
Copy link
Contributor

Jurigag commented Jan 16, 2017

Yes but read @andresgutierrez comments, eager loading is bad for performance and caching.

@sergeyklay sergeyklay changed the title Feature, relation chain [NFR] Relation chain Jan 16, 2017
@grigoriy-ivanov
Copy link

But question of eager loading is asked regularly. Maybe, the best solutions is implementation but with notification to developers about performance issues.

@Jurigag
Copy link
Contributor

Jurigag commented Jan 16, 2017

This is why eager loading is already in incubator.

@grigoriy-ivanov
Copy link

grigoriy-ivanov commented Jan 16, 2017

Eager loading in incubator have two issues:

  1. It does not work correctly with getters/setters in model;
  2. Eager Result not saved as reusable records in Models Manager

Prevents to resolve these issues: https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model/manager.zep#L1352
How to emulate unique_key in PHP?

@sergeyklay
Copy link
Member

Feel free to send PR with fixes for 1 and 2

@stale
Copy link

stale bot commented Apr 16, 2018

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

@stale stale bot added the stale Stale issue - automatically closed label Apr 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issue - automatically closed
Projects
None yet
Development

No branches or pull requests

4 participants