Help Needed for Nested Eager Loading Constraints

Solved Posted In Laravel
  • keshan-sandeepa 4 months ago
    I'm trying to fetch from the database nested query that's not in relationship with current model, In the attachment Division Model have a relationship with results , and results have relationship candidate , i need to fetch  the candidate result along with division result , how to do that?? please check the below image :   [https://drive.google.com/file/d/1vpRW43KHLDesTnE1tCo2xzqss4iXxg0b/view?usp=sharing](http://)
    

    I'm trying to fetch from the database nested query that's not in relationship with current model, In the attachment Division Model have a relationship with results , and results have relationship candidate , i need to fetch the candidate result along with division result , how to do that?? please check the below image : https://drive.google.com/file/d/1vpRW43KHLDesTnE1tCo2xzqss4iXxg0b/view?usp=sharing

  • Best Answer

    (As selected by keshan-sandeepa)

    keshan-sandeepa 4 months ago
    Okay I found some solution , In side the my model i added Eager loading by default , So even i fetch the data from Results its coming with default Relationship  
    So code look like this (controller). Let me know if you have any other method ! 
    
         $news2 =Division::with('results')
                ->with('districts')
                ->where([['result_released',1]])->get();
    						
    				Result Model
    				  protected $with = ['candidates'];
     

    Okay I found some solution , In side the my model i added Eager loading by default , So even i fetch the data from Results its coming with default Relationship
    So code look like this (controller). Let me know if you have any other method !

     $news2 =Division::with('results')
            ->with('districts')
            ->where([['result_released',1]])->get();
    					
    			Result Model
    			  protected $with = ['candidates'];
    
  • keshan-sandeepa 4 months ago
    Okay I found some solution , In side the my model i added Eager loading by default , So even i fetch the data from Results its coming with default Relationship  
    So code look like this (controller). Let me know if you have any other method ! 
    
         $news2 =Division::with('results')
                ->with('districts')
                ->where([['result_released',1]])->get();
    						
    				Result Model
    				  protected $with = ['candidates'];
     

    Okay I found some solution , In side the my model i added Eager loading by default , So even i fetch the data from Results its coming with default Relationship
    So code look like this (controller). Let me know if you have any other method !

     $news2 =Division::with('results')
            ->with('districts')
            ->where([['result_released',1]])->get();
    					
    			Result Model
    			  protected $with = ['candidates'];
    
  • cookie 3 months ago
    If you want to refactor your code a little bit, you can use a one-liner.
    
    Division::with(['results', 'districts'])->where(['result_released', true])->get();

    If you want to refactor your code a little bit, you can use a one-liner.

    Division::with(['results', 'districts'])->where(['result_released', true])->get();

  • scott-elliff 1 month ago
    > I'm trying to fetch from the database nested query that's not in relationship with current model, In the attachment Division Model have a relationship with results , and results have relationship candidate , i need to fetch the candidate result along with division result , how to do that?? please check the below image : [https://drive.google.com/file/d/1vpRW43KHLxg0b/view?usp=sharing via ](https://drive.google.com/file/d/1vpRW43KHLxg0b/view?usp=sharing)[essay typer online](https://essaytyper.pro/)
    
    Hi,
    
    I tried several methods. Similar topics and discussions which I checked while looking for a solution:
    * What's the best way to eager load nested relations while adding constraints on the parents? on Reddit
    * Nested eager loading constraints on StackOverflow.

    I'm trying to fetch from the database nested query that's not in relationship with current model, In the attachment Division Model have a relationship with results , and results have relationship candidate , i need to fetch the candidate result along with division result , how to do that?? please check the below image : https://drive.google.com/file/d/1vpRW43KHLxg0b/view?usp=sharing via essay typer online

    Hi,

    I tried several methods. Similar topics and discussions which I checked while looking for a solution:

    • What's the best way to eager load nested relations while adding constraints on the parents? on Reddit
    • Nested eager loading constraints on StackOverflow.
  • christine-howell 1 week ago
    A married status and all moments of the joy are introduced for the candidates. The student is intelligent and [aussie writer](https://aussiessayservices.com/aussiewriter-com-review/) for the visitors of the moves. True sense is built for the perfection. Appropriation is consumed for humans. section is felt for the way out of the full charge and all moves. tenet is done for struggle for the pars and all tips in the mid of the calculation for the entitlement for the parts for the proportion of substances.

    A married status and all moments of the joy are introduced for the candidates. The student is intelligent and aussie writer for the visitors of the moves. True sense is built for the perfection. Appropriation is consumed for humans. section is felt for the way out of the full charge and all moves. tenet is done for struggle for the pars and all tips in the mid of the calculation for the entitlement for the parts for the proportion of substances.

Please login or signup to leave a response.

Login

or Sign Up

Sign Up

or Login
×
Want to create your own SAAS?

I can teach you to create your own Software as a Service. Click here to learn more!

Visit SAAS Adventure!