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

Translation tables #94

delkano opened this issue Jan 13, 2020 · 2 comments

Translation tables #94

delkano opened this issue Jan 13, 2020 · 2 comments


Copy link

@delkano delkano commented Jan 13, 2020

I am trying to build a translatable API.
My ideal database architecture would be something akin to:
sometable (id, variousdata1, variousdata2, ...)
sometable_i18n (id, sometable, langcode, translateddata1, translateddata2, ...).

With such structure, I could for example find sometable id.1 with strings in languaage 'en' with a simple LEFT JOIN:
SELECT * FROM sometable LEFT JOIN sometable_i18n ON sometable_i18n.sometable = AND langcode='en' WHERE id=1

However, I am having some trouble seeing how to implement something like this in Cortex. Has any one some idea about how to do it, or any kind of alternative way?


This comment has been minimized.

Copy link

@ikkez ikkez commented Jan 14, 2020

This looks like a simple has relation to me. I.e. if there are multiple i18n entries regarding, it's a has-many <> belongs-to-one

SomeTableModel with $fieldconf:
'i18n' => ['has-many'=>['Sometable_i18nModel','sometable']]

and Sometable_i18nModel with
'sometable' => ['belongs-to-one'=>['SomeTableModel','id']]

to do the query:

$sometable = new Sometable();
$sometable->has('i18n', ['langcode = ?', 'en']);
$sometable->load(['id = ?', 1]);
foreach($sometable->i18n ?: [] as $i18n)
  echo $i18n->translateddata1;

In case it's a 1:1 relation, it's only has-one at the other end and $sometable->i18n->translateddata1 without a collection between.

@ikkez ikkez added the question ⁉ label Jan 14, 2020

This comment has been minimized.

Copy link
Contributor Author

@delkano delkano commented Jan 17, 2020

I was definitively overthinking this. Thank you.

@delkano delkano closed this Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.