laravel_cities icon indicating copy to clipboard operation
laravel_cities copied to clipboard

Bug in parent

Open brunobg opened this issue 4 years ago • 11 comments

I ran these two commands:

artisan geo:seed US --append
artisan geo:seed BR --append

When using the CityPicker states and cities mixed up, from individual US.txt and BR.txt. Importing the whole countries database did not result in this behavior. Is this something expected or a bug? Any workarounds?

brunobg avatar May 04 '20 15:05 brunobg

What do you mean by "mixed"? Do they appear to belong to a single country?

igaster avatar May 05 '20 04:05 igaster

Yes, when I use the vue component, here's what happens:

  1. select country US
  2. states from US are loaded
  3. change country to BR
  4. states from BR are loaded and mixed with US.

I though this might be a bug in the vue component, bu the same behavior does not happen if the entire country DB is loaded at once, only when one country is loaded and then another is appended.

brunobg avatar May 05 '20 18:05 brunobg

Actually, even with the entire import I'm getting some strange results.

/geo/ancestors/3469034 returns not only Brazilian states, but also those from Portugal and Poland.

brunobg avatar May 05 '20 20:05 brunobg

apparently there's something buggy in parent. /geo/item/3665474 is correct (Acre, state of Brazil), but /geo/parent/3665474 returns Poland (798544) when the correct parent is Brazil (3469034). parent_id is correct in /geo/item, so it does seem like a bug in the code.

brunobg avatar May 05 '20 22:05 brunobg

Yep, definitely bugged. The PR #33 fixes Geo::parent, but ancestors is returning data that it shouldn't. I didn't stop to read how you build your tree with left/right. I'd really appreciate if you could fix this or at least give me a few pointers, as this is a showstopper bug with the vue component. Your lib is very helpful, let's fix this :)

brunobg avatar May 05 '20 22:05 brunobg

Thanks for the PR... I will check this in the weekend and run some tests...

The left/right columns are actually important to calculate the parents/children. This is a reference of how it works: Nested Set Model

igaster avatar May 06 '20 04:05 igaster

Hey, did you get a chance to look at this?

brunobg avatar Jun 10 '20 17:06 brunobg

Just to add some info and confirmation I am seeing a bug which sounds like it relates to this issue;

I choose 'United Kingdom' and the top level dropdown is replace with Poland.

I choose another such as Republic of Yemen and 3 dropdowns below pre-filled with unrelated places.

wrabit avatar Jun 21 '20 11:06 wrabit

@wrabit Check my for to see if fixes your bugs https://github.com/Corollarium/laravel_cities

@igaster do you still plan to check this? If not please let me know and I'll make a separate package with my fork.

brunobg avatar Jun 23 '20 20:06 brunobg

@brunobg how can I pull in your version to my project? (tried setting up your repo in my composer.json and requiring it but no joy)

wrabit avatar Jun 23 '20 23:06 wrabit

@wrabit follow the composer instructions: https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository

If there's no response here I'll release my fork on composer. But I'm not using the tree, so I'd need to remove it from the code and it will take a bit of time that I don't have right now. Would you be up to give some help for that? It's essentially removing code.

BTW, in my application I'm using the '/children/' + geoId and the /countries endpoints, which are working properly. I changed the vue file significantly, removing calls to ancestors which is slower and I think still buggy IIRC. My component is simpler than the code here, but it works as expected to select cities. I didn't commit it yet, let me know if you want it.

brunobg avatar Jun 24 '20 18:06 brunobg