# |
Jul 12th 2017, 21:25 |
ericadeefox |
^^ty for this, I am so bad at convention |
# |
Jul 12th 2017, 21:23 |
chris-andre |
Just to give you an input on join tables, according the docs: >Join tables, used in BelongsToMany relationships between models, should be named after the model tables they will join, arranged in alphabetical order (articles_tags rather than tags_articles). |
# |
Jul 12th 2017, 21:22 |
ericadeefox |
^^oh no that's much better, to have a users_groups and a users_friendships |
# |
Jul 12th 2017, 21:20 |
chris-andre |
That would be "easier". That would be a groups (or something similar) with groups_users. |
# |
Jul 12th 2017, 21:19 |
ericadeefox |
@chris-andre ahh good point if there are just 2 users per friendship, I was thinking a "friendship" would have >= 2 users, as many as necessary lol |
# |
Jul 12th 2017, 21:18 |
chris-andre |
@konstanting I would go for one table named whatever (friendships) with id:integer user_a:integer user_b:integer. Two rows for one friendship should not be necessary. Now, I'm haven't thought about the a nice cake-way to create the association. |
# |
Jul 12th 2017, 21:16 |
ericadeefox |
in the Friendships model, you'd put that Friendships entities have many Users entities. in this instance, a Friendship is just, like, an entity that multiple Users can collaborate on. no different than if an article had multiple authors for example. |
# |
Jul 12th 2017, 21:14 |
ericadeefox |
if UserA and UserB have Friendship1, then that's how they relate. in `users_friends`, there'd be a row for UserA and Friendship1, and a separate row for UserB and Friendship1 |
# |
Jul 12th 2017, 21:13 |
konstanting |
```$this->belongsToMany('Friends', [ 'className' => 'Users', 'joinTable' => 'users_users', 'targetForeignKey' => 'friend_id' ]);``` |
# |
Jul 12th 2017, 21:13 |
konstanting |
Maybe the following makes it clearer |
# |
Jul 12th 2017, 21:13 |
konstanting |
@ericadeefox But what would I put in the Friendships Model? If I want relate UserA to UserB I need to connect these Models and not another one. |
# |
Jul 12th 2017, 21:12 |
ericadeefox |
gbye @sturm!! :) |
# |
Jul 12th 2017, 21:12 |
saeideng |
good by |
# |
Jul 12th 2017, 21:12 |
saeideng |
goof by |
# |
Jul 12th 2017, 21:11 |
sturm |
End of workday; I’m heading home. See you all tomorrow, most likely. |
# |
Jul 12th 2017, 21:10 |
saeideng |
if your table is `users_friends` you should use `users_friends`] |
# |
Jul 12th 2017, 21:09 |
ericadeefox |
you want many users to be able to have many friendships, and many friendships to be able to have many users, like social media yes? those 'Friendships' are entities also and need their own models. |
# |
Jul 12th 2017, 21:08 |
ericadeefox |
probably, I'm horrible at following convention. @konstanting you're gonna want a model for your 'Friendships' as well. |
# |
Jul 12th 2017, 21:08 |
sturm |
Also, @ericadeefox, doesn’t the join table have to be in alphabetical order? i.e., `friends_users` instead of `users_friends`? Not sure if it makes that much of a difference, though. |
# |
Jul 12th 2017, 21:08 |
konstanting |
@ericadeefox No it's just imaginary |
# |
Jul 12th 2017, 21:07 |
ericadeefox |
@konstanting do you have a model built for 'Friendships'? |
# |
Jul 12th 2017, 21:06 |
sturm |
Okay, thanks @saeideng. |
# |
Jul 12th 2017, 21:06 |
ericadeefox |
yes, 'localproject' in this case would be the same as your 'friendship's. |
# |
Jul 12th 2017, 21:06 |
konstanting |
I think the Problem with my relation ist that It relates to the User Modal in both directions |
# |
Jul 12th 2017, 21:06 |
konstanting |
@ericadeefox Is "localproject" a Model too? |
# |
Jul 12th 2017, 21:05 |
ericadeefox |
``` $this->belongsToMany('Users', [ 'foreignKey' => 'localproject_id', 'targetForeignKey' => 'user_id', 'joinTable' => 'users_localprojects' ]);``` |
# |
Jul 12th 2017, 21:04 |
ericadeefox |
this is a similar snippet of code from a many-to-many relation in something that was left untouched after I just baked it: |
# |
Jul 12th 2017, 21:03 |
konstanting |
@ericadeefox If I delete this line it won't work at all |
# |
Jul 12th 2017, 21:03 |
saeideng |
within `request` tab |
# |
Jul 12th 2017, 21:03 |
nicolas.r |
it creates autommaticly model and relations |
# |
Jul 12th 2017, 21:03 |
nicolas.r |
no probleme like dat |
# |
Jul 12th 2017, 21:03 |
saeideng |
also you can see these params on debug_kit panel |
# |
Jul 12th 2017, 21:02 |
nicolas.r |
@konstanting personnaly i create my schema db with SQL and I do a cake bake model myModel |
# |
Jul 12th 2017, 21:02 |
ericadeefox |
@konstanting try getting rid of `'className' => 'Users'` |
# |
Jul 12th 2017, 21:02 |
saeideng |
so if you want first key/value of that you need use getParam(pass.0) |
# |
Jul 12th 2017, 21:01 |
saeideng |
`getParam('pass')` returned `[0=>1,1=>2,2=>3.3=>4]` |
# |
Jul 12th 2017, 21:01 |
slackebot |
'friend_id' ]);``` |
# |
Jul 12th 2017, 21:01 |
konstanting |
Hey folks, I'm trying to do a many to many relation in cake3 on one model. So one users can have many friends(users). I got it to work in one direction but not the other way around. Has anyone ever encountered a similar problem? Relation looks like this: ``` $this->belongsToMany('Friendships', [ 'className' => 'Users', 'joinTable' => 'users_friends', 'targetForeignKey' => 'user_id', ' |
# |
Jul 12th 2017, 21:00 |
saeideng |
when you have url like `site.com/users/show/1/2/3/4` |
# |
Jul 12th 2017, 20:59 |
saeideng |
i understand your question now from `$this->request->getParam('pass.0');` |
# |
Jul 12th 2017, 20:55 |
nicolas.r |
yup thx |