mercredi 30 décembre 2015

n-n relationship with an additional value for the same table in laravel

I'm quite new to Laravel, and I'm trying to figure the correct way to design my database schema before starting anything.

So, here is the deal :

  • I'm creating an application on which users should have to create an account. I'll need a users model/db table. No problem here.
  • These users will be able to mention some of their friends. These friends should then be able to register and become legitimate users, or they won't.
  • I wanted first to make two tables, but as the friends can become users as well, I thought adding them to the users table was quite logical (With something like a unregistered flag while they are not registered).

The catch is, I think Laravel is able to make automatically a correct n-n relationship between users and users, but I also wanted to allow the first users to add a pseudonym for their friends. In a "regular" database, I'd add the pseudonym field in the relationship database, but is it possible with Laravel, and how ?

After reading myself, I'm maybe not very self-explanatory. Si, here are the possible user stories :

  • I create my account
  • I mention my friend bob with his email, it creates a new user with only the email, and a relationship between me and bob in where I call him "friend"
  • Alice creates her account, and mentions bob. It links her user account with bob's, but in the relashionship table she calls him "sweetie"
  • Bob creates his account. Its users database entry is completed with his personal information / pseudonym, but Alice and I still see him as friend/sweetie

Sorry for being this talkative.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire