Support the ongoing development of Laravel.io →
posted 10 years ago
Database
Last updated 2 years ago.
0

The area in the documentation you're looking for is Eager Loading.

Essentially, you can have relational methods on your building model for each of the tables that it relates to, for example, joining your Buildings with the Building Data would be

class Building extends \Eloquent {

    public function building_data() {
        return $this->hasOne('BuildingData'); // Where BuildingData is the class name of your building_data model
    }

}

Then when querying a building elsewhere you can do

Building::with('building_data')->get();

And it will include everything in the with in the initial query, leading to less calls. You can put as many methods in the with() call as you like.

It should be noted that I don't really understand why you separated Building_Data from Building. The relationship looks 1-to-1 to me, and wouldn't every building have a name? Seems like this schema is aggressively trying to split data down lines that it doesn't actually need to. Just my 2 cents.

Last updated 2 years ago.
0

Thank you. That's what I was looking for :)

Hm, when I combine buildings and building_data, in every row of buildings would be written the name of the building (or the description of it). If you have 1,000 rows you have 1,000-times the name of the building. If you change the name you have to alter 1,000 rows.

But if you seperate it into two tables, you just need to update one row which is way better for the performance. At least, that is what I thought.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

d3mueller d3mueller Joined 29 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.