5
I’m setting up a land registry, where these properties belong to an address, which belongs to a neighborhood that belongs to a city.
Ex tables:
Imoveis: id, endereco_id, etc...
Enderecos: id, nome, bairro_id, rua, numero, cep, etc...
Bairros: id, nome, cidade_id
Cidades: id, nome;
However, if I want to perform a real estate search in a registered city, as this relationship is, it is valid to duplicate the key within Immoveis, creating a city_id?
First situation: When searching selects, I want to list only cities that have registered properties.
Second situation: Select the city and list via ajax the neighborhoods that have property registration.
Third situation: search the properties and list along with them, their addresses, neighborhood and city.
Any idea how to work this data better, and whether I’m on the right track?
Note: I am not asking for ready queries, but ideas on how to best implement this relational model, where the registration of each neighborhood and city will be done along with other property information, consistently saving the names of neighborhoods and cities, avoiding the double registration of these.
My first question would be whether you really need to have this address normalization. Do you have any need or advantage? Can a property be in more than one address? There is a reason the address is separate?
– Maniero
Regarding the redundancy of
id
s, you might be interested in: http://answall.com/q/22208/7261 You may choose to have a column[tabela]_id
redundant or useJOIN
to make the query filtering by city. In the second situation, you can use aLEFT JOIN
orRIGHT JOIN
– user7261
@bigown A property belongs to a unique address. It is separate because the immovable table is large, and because I will not always call Addresses... There is the question of cascading update, if remove a city, or neighborhood, should go all that belongs to him/her together.
– Marcelo Aymone
@Marcelo (only one comment...) for this would be enough to select the fields to use in select, not necessarily need to separate the table.
– Bacco
But for performance purposes, the smaller the table, there is no better performance in
selects
?– Marcelo Aymone
@Marceloaymone You tried both ways and measured if you won? Having to access data in two places worsens performance. If the table is smaller can have performance gain. But only if all data are in it. Separate can even organize a little more, this is it. But it’s rare to need this entire organization.
– Maniero
@Marceloaymone what will give the performance is index, and the amount of data that travels through the interface. There may even be a difference in file separation depending on the form you organize (for better or worse), but to worry about this type of adjustment, only in an immense or very critical application (it would involve a more complex analysis of the case).
– Bacco
Okay, actually, separate or unaddressed would not be my focus of the question but rather as to cities and neighborhoods, etc.
– Marcelo Aymone
I didn’t answer because you already got an answer. Except for the separate address, your modeling is fine, just do the darlings correctly. In the answer has a good basis to do. City and Neighborhood are entities and not a description, so you did the correct. Then you’ll have to see if you can implement any way to find nearby neighborhoods in a radius. It’s much more complicated but it’s very useful and many sites like this implement it. It was just an idea for you.
– Maniero
I had thought of this @bigown, it’s really quite interesting to look for proximity. Allows the user more search dynamicity, I will condense immovable and address in the same table and try to follow with neighborhood and city as entities.
– Marcelo Aymone
@Marceloaymone even because they are really entities. Better register the new neighborhood when you need, than become a mess. A reminder: neighborhood is city entity, and not the general register. This facilitates even more the organization. Even if two neighborhoods have equal names in different cities (or the Center, for example), treating separately is conceptually better. " coincidence" should not be converted into rule ;)
– Bacco
It is worth taking a look here: http://answall.com/questions/622/qual-a-bestmanly-de-se-represent- um-addressees%C3%A7o
– bfavaretto