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

(hasMany->belongTo) Which one to choose for these relationships? #49

Closed
nekooee opened this issue Oct 17, 2019 · 5 comments
Closed

(hasMany->belongTo) Which one to choose for these relationships? #49

nekooee opened this issue Oct 17, 2019 · 5 comments

Comments

@nekooee
Copy link

nekooee commented Oct 17, 2019

Hi Dear,
I have these relations:
Article->(hasMany)Translate->(belongTo)translator
I need to Article->translators() and reverse

thanks

@staudenmeir
Copy link
Owner

Please post the two individual relationships or the structure of all three tables.

@nekooee
Copy link
Author

nekooee commented Oct 17, 2019

translators :

id
name

articles :

id

article_translations :

id
locale
title
article_id
translator_id

I need to Article->translators() and reverse Translators->articles()

thank you

@staudenmeir
Copy link
Owner

That's a standard BelongsToMany relationship:
https://laravel.com/docs/eloquent-relationships#many-to-many

@nekooee
Copy link
Author

nekooee commented Oct 17, 2019

But the translators have no direct relationship to the articles. I want to get articles with a specific translator as well as all the articles with a specific translator.

@staudenmeir
Copy link
Owner

But the translators have no direct relationship to the articles.

They are connected by the pivot table.

@nekooee nekooee changed the title (OneToMany->OneTo One) Which one to choose for these relationships? (hasMany->belongTo) Which one to choose for these relationships? Oct 18, 2019
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

No branches or pull requests

2 participants