Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use deep merge for column info when adding columns #128

Open
wants to merge 1 commit into
base: maint/0.0828xx
Choose a base branch
from

Conversation

robrwo
Copy link

@robrwo robrwo commented Jul 31, 2018

The add_columns method uses a shallow merge of column
information. But the problem is that information in
"extra" is overwritten rather than merged.

This fixes the following issue:

__PACKAGE__->add_column(
  x => {
    data_type => 'enum',
    extra     => {
      list => [qw/ success fail /],
    }
  }
);

__PACKAGE__->add_column(
  '+x' => {
    extra => {
      something_else => ...
    }
  }
);

The add_columns method uses a shallow merge of column
information.  But the problem is that information in
"extra" is overwritten rather than merged.

This fixes the following issue:

    __PACKAGE__->add_column(
      x => {
        data_type => 'enum',
        extra     => {
          list => [qw/ success fail /],
        }
      }
    );

    __PACKAGE__->add_column(
      '+x' => {
        extra => {
          something_else => ...
        }
      }
    );
@robrwo
Copy link
Author

robrwo commented Jul 31, 2018

If using Hash::Merge is not considered palatable, then an alternative might be to merge the extra columns separately using a _merge_column_info method that can handle the "extra" key.

@ribasushi
Copy link
Collaborator

The more important issue here is that it is not clear cut what does handle the "extra" key actually mean. Currently if one wants to rewrite the extra contents, they can do it with a +foo. After your patch - they will no longer be able to.

As your patch came without an extensive test case, it is difficult for me to figure out what your use case is. I suspect that you simply find the behavior you are proposing a better default, and could do what you want today instead as:

__PACKAGE__->add_column(
  '+foo' => { ... extra => {
    %{ __PACKAGE__->column_info("foo")->{extra} || {} }
    < extra stuff above or below this line depending whether you want override or default else >
  } }
);

I am in general very disinclined changing established behavioral defaults. Please explain in more detail why this case warrants an exemption.

P.S. I am leaving on a week-long trip: might not read/respond for a while

@robrwo
Copy link
Author

robrwo commented Jul 31, 2018

@ribasushi Good point about users overwriting "extra" vs merging.

How about, it keeps the current behaviour, but if the column info has a "+extra" field, then it merges that instead of overwriting it?

FYI, the use case is for DBIC::Helper::Row::Enumeration, so that devs can override default handlers. I thought adding configuration in "extra" made sense.

@ribasushi ribasushi force-pushed the maint/0.0828xx branch 2 times, most recently from 1245f48 to c11281c Compare October 30, 2019 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants