Jump to content

Archived

This topic is now archived and is closed to further replies.

Ortix

Most efficient database structure for laravel

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!
*/

Share this post


Link to post
Share on other sites

×
×
  • 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.