Jump to content

Most efficient database structure for laravel


Ortix

Recommended Posts

Hi guys i'm currently developing a small application with laravel 4 and I have noticed that in its current incarnation it's not functioning as supposed.

 

A quick description of the app. It's kind of a tinder like app but it's only for facebook friends. Basically, you go to the site, login with your facebook account. Your entire facebook friendlist will be loaded from which you can pick 3 friends whom you like. They can then do the same (not knowing you did any of this) and if they click/like you back both will be notified.

 

The way it works is that when you log in, a profile is created in the database in the profiles table. In the table your facebook id is stored. This id is important for matching.

 

Now the way I have it set up is with a clicks table. This contains 3 fields. id, clicker and clickee. In the clicker and clickee fields, facebook id's are stored. Your are the clicker, the persons you click are the clickees. So if you select 3 people, 3 entries will be created in the database. The reason that I'm storing facebook id's is because the user you select most probably does not have a user account on the my application site. Hence the matching must be done with facebook id's.

 

Now i've spammed laravel's forums and irc with my ORM problems. I can't seem to retrieve the profile of the clickee's. (for your matches page). I'll post my code below, but perhaps someone has a better and more efficient way of handling this as far as sql goes.

 

Tables architecture:

clicks->id

clicks->clicker

clicks->clickee

 

profiles->id

profiles->name

profiles->username

profiles->uid (facebook profile id)

class Click extends Eloquent {

    public function profile() {
        return $this->belongsTo('Profile','clickee','uid');
    }

class Profile extends Eloquent {

    public function click() {
        return $this->hasMany('Click','clickee', 'uid');
    }

The $clicks variable itself is not empty; that contains the correct rows

$clicks = Click::where('clickee', '=', $uid)->get();
$clicks[0]->profile; //returns null
$clicks = Click::find(1);
var_dump($clicks->profile); // returns null

$queries = DB::getQueryLog(); 
dd(end($queries)); //returns the following:

array (size=3)
  'query' => string 'select * from `profiles` where `profiles`.`id` = ? limit 1' (length=58)
  'bindings' => 
    array (size=1)
      0 => string '100000898436106' (length=15)
  'time' => float 0.24
/**
Note the red "id". That should be uid... Then it will work!
*/
Edited by Ortix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.