[POC] rails attribute for ancestor_ids#481
[POC] rails attribute for ancestor_ids#481kbrock wants to merge 5 commits intostefankroes:masterfrom
Conversation
| elsif value.nil? || value.kind_of?(String) | ||
| value | ||
| else | ||
| byebug |
There was a problem hiding this comment.
i think we want to handle this case a little differently
5 similar comments
extract the % string. this is materialized path only, but it is nice to distinguish between my child, and my descendants
ancestry is now an array ancestor_ids are going to merge with ancestry
goal is to have all methods relative to ancestor_ids if possible names will contain ancestor_ids then, we may be able to configure this to have multiple parents
|
this turns out to not be trivial to rebase and bring forward. frustrating the issue I have here is rails 5.1(?) and earlier don't handle the serialization that well - refusing to cache it and not properly detecting when the value has changed. Well, to be more precise, not detecting when the value has not changed. It also does not cache the casting so quite a few more objects are created. I would prefer a way to make the attribute look more like a rails database parameter. The integration points are close but not quite there in rails proper. Requires just a little too much monkey patching. i do have a modified version of activerecord-virtual_attributes that is more native. but again, it is close but still requires too many monkey patches. |
|
so it looks like there are a few things to do for this Determine whether we want to expose
|
|
stalled: ancestry column becomes an array. so the concept of ancestor_ids and ancestry merge. Which I guess makes sense because the slash delimiter was just a database serialization artifact. problem: lots of people expect the ancestry column to have a slash delimiter. So having it converted to an array will mess with them. Not sure how to be backwards compliant in this concept |
| # convert to database type | ||
| def serialize(value) | ||
| if value.kind_of?(Array) | ||
| value.map(&:to_s).join(@delimiter).presence |
There was a problem hiding this comment.
not sure if we want an empty ancestry to have [] or nil
technically null means that the value is undetermined. But in our case, we want to say "none" which is "" and not nil.
|
our main code base has move to using I have had trouble bringing this up to date. Have tried a few times. |
|
surprisingly this has been difficult to fix the merge conflicts. |
|
this is imposible to rebase. Keeping around but will need to completely rewrite this when I get the chance |
Rails has a concept of serializing attributes. They even allow you to define a custom serializer.
So the concept of
ancestryandancestor_idsare merged, and the delimiter basically goes away.So from there, I merged them over to the
ancestor_idsconcept and saw if it was possible to rename fields based upon ancestor_ids. If this is possible, it may be possible to have multiple ancestors.Dropping 4.2 to simplify this support.