Skip to content

Instantly share code, notes, and snippets.

@phalcon
Created December 17, 2012 20:35
Show Gist options
  • Save phalcon/4321955 to your computer and use it in GitHub Desktop.
Save phalcon/4321955 to your computer and use it in GitHub Desktop.
<?php
/* desc artists_similar;
+-------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| artists_id | int(10) unsigned | NO | MUL | NULL | |
| similar_artist_id | int(10) unsigned | NO | | NULL | |
+-------------------+------------------+------+-----+---------+----------------+
*/
class ArtistsSimilar extends Phalcon\Mvc\Model {
public function initialize(){
$this->belongsTo('artists_id', 'Artists', 'id', array(
'alias' => 'artist'
));
$this->belongsTo('similar_artist_id', 'Artists', 'id', array(
'alias' => 'similarArtist'
));
}
}
/* Using getters */
$artist = ArtistsSimilar::findFirst()->getArtist();
$similarArtist = ArtistsSimilar::findFirst()->getSimilarArtist();
/* PHQL */
$phql = "SELECT * FROM ArtistsSimilar JOIN Artists WHERE id = 100";
$em->executeQuery($phql);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment