stefankroes / ancestry

Organise ActiveRecord model into a tree structure
MIT License
3.71k stars 458 forks source link

fix: `rebuild_counter_cache!` primary key cast problem #665

Closed RongRongTeng closed 1 year ago

RongRongTeng commented 1 year ago

Fix

Currently, when the primary key consists of more than one character and casts to CHAR without a specific length, it can lead to problems. This occurs because the default length for CHAR is 1, which may not be sufficient to accommodate the values of the primary key.

To resolve this issue, this PR changes casting the primary key column to VARCHAR.

kbrock commented 1 year ago

this looks great. wonder why it did not run tests

kbrock commented 1 year ago

kicking. trying to get the build to run

kbrock commented 1 year ago

I have a few ideas to improve these tests.

looks like VARCHAR will not work with mysql, but I think I can get the casts using concat() or something like that.

I'll open a PR based upon your commits and ping you shortly

kbrock commented 1 year ago

Please let me know if #668 meets your needs.

I gave you attribution for one of the commits but had to change it a bit. Please tell me if you are not ok with the changes I made to your code.

RongRongTeng commented 1 year ago

Please let me know if #668 meets your needs.

I gave you attribution for one of the commits but had to change it a bit. Please tell me if you are not ok with the changes I made to your code.

Thanks! It meets my needs 🙏🏻 This bug occurs when using PostgreSQL. I will close this PR.