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

Comments

Projects
None yet
4 participants
@grzegorz-pierzakowski

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

This comment has been minimized.

Member

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

This comment has been minimized.

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

This comment has been minimized.

Member

Jurigag commented Jan 16, 2017

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

@sergeyklay sergeyklay changed the title from Feature, relation chain to [NFR] Relation chain Jan 16, 2017

@grigoriy-ivanov

This comment has been minimized.

grigoriy-ivanov commented Jan 16, 2017

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

@Jurigag

This comment has been minimized.

Member

Jurigag commented Jan 16, 2017

This is why eager loading is already in incubator.

@grigoriy-ivanov

This comment has been minimized.

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

This comment has been minimized.

Member

sergeyklay commented Jan 16, 2017

Feel free to send PR with fixes for 1 and 2

@stale

This comment has been minimized.

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 label Apr 16, 2018

@sergeyklay sergeyklay closed this Apr 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment