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

Feature/output group #8

Closed
wants to merge 3 commits into from
Closed

Feature/output group #8

wants to merge 3 commits into from

Conversation

mringler
Copy link
Owner

@mringler mringler commented Apr 18, 2024

Allows declaring output groups on columns and foreign key relations in schema.xml. Passing a group name to the toOutputGroup() method on the model or ObjectCollection returns an array holding all values defined by the group name.

So in schema.xml:

<table name="le_table">
  <column name="col1" outputGroup="foo,bar" />
  <column name="col2" />
  <foreign-key phpName="fk" outputGroup="foo">
    ...

On an object:

leTableObject->toOutputGroup('foo'); // will return ['Col1' => ..., 'Fk' => ...]
leTableObject->toOutputGroup('bar'); // will return ['Col1' => ...]

Instead of a group name, an array with model class names can also be used:

leTableObject->toOutputGroup([
  LeTable::class => 'foo',
  'default' => 'bar'
]);

It automatically skips recursive output:

toArray toOutputGroup
[
  'event' => [
    'event_id' => 1,
    'event_type' => [
      'event_type_id' => 1,
      'events' => [[*RECURSION*]]
    ]
  ]
]
[
  'event' => [
    'event_id' => 1,
    'event_type' => [
      'event_type_id' => 1,
    ]
  ]
]

I find this much easier than using a serializer as I don't have to re-iterate all columns in another file.

@mringler mringler force-pushed the feature/output_group branch 3 times, most recently from 403537c to d1477b9 Compare April 18, 2024 18:43
@mringler mringler closed this Apr 22, 2024
@mringler
Copy link
Owner Author

closed in favor of #9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant