SHARE
TWEET

Untitled

a guest May 21st, 2017 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Schema:
  2.  
  3. Comment:
  4.   tableName: comment
  5.   actAs:
  6.     Timestampable:
  7.   columns:
  8.     id:
  9.       type: integer(4)
  10.       primary: true
  11.       notnull: true
  12.       autoincrement: true
  13.     comment:
  14.       type: string(500)
  15.     user_id:
  16.       type: integer(4)
  17.     story_id:
  18.       type: integer(4)
  19.     video_id:
  20.       type: integer(4)
  21.   relations:
  22.     User:
  23.       local: user_id
  24.       foreign: id
  25.       foreignAlias: Comments
  26.       class: sfGuardUser
  27.       onDelete: cascade
  28.       onUpdate: cascade
  29.     Story:
  30.       local: story_id
  31.       foreign: id
  32.       foreignAlias: StoryComments
  33.       onDelete: cascade
  34.       onUpdate: cascade
  35.     Video:
  36.       local: video_id
  37.       foreign: id
  38.       foreignAlias: VideoComments
  39.       onDelete: cascade
  40.       onUpdate: cascade
  41.  
  42. SfGuardUserProfile:
  43.   tableName: sf_guard_user_profile
  44.   columns:
  45.     id:
  46.       type: integer(4)
  47.       primary: true
  48.       notnull: true
  49.       autoincrement: true
  50.     first_name:
  51.       type: string(64)
  52.     last_name:
  53.       type: string(64)
  54.     user_id:
  55.       type: integer(4)
  56.     company:
  57.       type: string(64)
  58.     profile_text:
  59.       type: clob(65535)
  60.     picture:
  61.       type: string(64)
  62.   relations:
  63.     User:
  64.       local: user_id
  65.       class: sfGuardUser
  66.       foreign: id
  67.       foreignAlias: Profile
  68.       onDelete: cascade
  69.       onUpdate: cascade
  70.       foreignType: one
  71.   options:
  72.     type: InnoDB
  73.  
  74. sfGuardUser:
  75.   actAs: [Timestampable]
  76.   columns:
  77.     id:
  78.       type: integer(4)
  79.       primary: true
  80.       autoincrement: true
  81.     username:
  82.       type: string(128)
  83.       notnull: true
  84.       unique: true
  85.     algorithm:
  86.       type: string(128)
  87.       default: sha1
  88.       notnull: true
  89.     salt: string(128)
  90.     password: string(128)
  91.     is_active:
  92.       type: boolean
  93.       default: 1
  94.     is_super_admin:
  95.       type: boolean
  96.       default: false
  97.     last_login:
  98.       type: timestamp
  99.   indexes:
  100.     is_active_idx:
  101.       fields: [is_active]
  102.   relations:
  103.     groups:
  104.       class: sfGuardGroup
  105.       local: user_id
  106.       foreign: group_id
  107.       refClass: sfGuardUserGroup
  108.       foreignAlias: Users
  109.     permissions:
  110.       class: sfGuardPermission
  111.       local: user_id
  112.       foreign: permission_id
  113.       refClass: sfGuardUserPermission
  114.       foreignAlias: Users
  115.  
  116.  
  117.  
  118. Query:
  119.     return $this->createQuery('sc')
  120.             ->leftJoin('sc.User u')
  121.             ->leftJoin('u.Profile p')
  122.             ->where('sc.video_id = ?',$id)
  123.             ->orderBy('sc.created_at DESC')
  124.             ->useResultCache(true,sfConfig::get('app_story_comment_cache'),'comment_'.$id.'_'.$page);
  125.  
  126. Html:
  127.   <?php foreach($pager->getResults() as $comment): ?>
  128.     <li><?php echo $comment->getUser()->getProfile()->getDisplayName();?> said at <?php echo $comment->getCreatedAt();?> -
  129.         <?php echo $comment->getComment();?>
  130.     </li>
  131.   <?php endforeach;?>
  132.  
  133. Results in 4 queries(one for each of the getProfile()->getDisplayName()
  134.  
  135. If you drop off the useResultCache it results in one query, the very first one.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top