Skip to content

Models should have a meta accessor #6200

Open
@jonwaldstein

Description

@jonwaldstein

Details

As we build our concept of models, we'll need to include a way to access and persist related meta information that's not core to said model. For instance, our Donation model will include things like amount from it's meta that will be a core property. For meta that exists externally from add-ons that is not necessarily core to the model, we'll want a specific meta accessor.

Additional Context

Proposed Solution

  • Create an abstract Meta class that models can extend assign as their meta property
  • Have an easy way to get and set meta

Examples scaffolded from conversation with @JasonTheAdams

// Note that the meta does not save until the donation itself saves. Like the donation, the assigned meta values are
// simply stored until told to persist.
$donation = Donation::find(1);

$foo = $donation->meta->foo;

$donation->meta->bar = true;
$donation->meta->baz = 42;
$donation->save();
// retrieve value from single row
$donation->meta->get('my-value');
$donation->meta->my_value;
$donation->meta->myValue;

// save single row
$donation->meta->myValue = 123;
$donation->meta->set('my-value', 456);
$donation->meta->myArray = [1,2,3];

// retrieve from multiple rows
$donation->meta->getMany('my-values');

// save as multiple rows
$donation->meta->setMany('my-values', [1,2,3]);

Acceptance Criteria

  • Models have a way to access and persist meta

Metadata

Metadata

Labels

keep-fresh"Keep Fresh" issues should not be marked as stale.type: enhancementAn improvement to existing user-facing functionality

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions