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

Models should have a meta accessor #6200

Open
1 task
jonwaldstein opened this issue Feb 1, 2022 · 3 comments
Open
1 task

Models should have a meta accessor #6200

jonwaldstein opened this issue Feb 1, 2022 · 3 comments
Assignees
Labels
keep-fresh "Keep Fresh" issues should not be marked as stale. type: enhancement An improvement to existing user-facing functionality

Comments

@jonwaldstein
Copy link
Contributor

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
@jonwaldstein jonwaldstein added the type: enhancement An improvement to existing user-facing functionality label Feb 1, 2022
@github-actions
Copy link

github-actions bot commented Dec 2, 2022

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 14 additional days.

@github-actions github-actions bot added the Stale label Dec 2, 2022
@jonwaldstein
Copy link
Contributor Author

This is still something I would like to think through more.

@JasonTheAdams JasonTheAdams added keep-fresh "Keep Fresh" issues should not be marked as stale. and removed Stale labels Dec 2, 2022
@JasonTheAdams
Copy link
Contributor

JasonTheAdams commented Dec 2, 2022

Just to quickly job down my thoughts. I think something like:

  • $donation->meta->some_meta_key;
  • $donation->meta->get('funky-key name');
  • $donation->meta->getAll('multi-row-meta');
  • $donation->meta->eagerLoad('keys', 'to', 'preload', 'all at once');
  • $donation->meta->cache(['meta key to store' => 'the value to store']);

Meta is retrieved on the fly and cached in the instance. If the value exists in the cache, then it's used instead of querying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep-fresh "Keep Fresh" issues should not be marked as stale. type: enhancement An improvement to existing user-facing functionality
Projects
None yet
Development

No branches or pull requests

3 participants