Jump to content

[SOLVED] Joing tables using a classs in the Zend Framework?


Recommended Posts

Hi everyone,


I have a database with the looks like the following;




I have created the model below


* Description of gallery
* @author lv
class Model_DbTable_Artist extends Zend_Db_Table_Abstract
    protected $_name = 'artist';

class Model_DbTable_Image extends Zend_Db_Table_Abstract
    protected $_name = 'image';

class Model_DbTable_Category extends Zend_Db_Table_Abstract
    protected $_name = 'category';
    protected $_referenceMap    = array(
        'ArtistCategory' => array(
        'columns'           => 'artist_id' , 'category_id',       
        'refTableClass'     => 'Artist', 'Category',
        'refColumns'        => 'artist_id' , 'category_id',     
        'ImageCategory' => array(
        'columns'           => 'image_id' , 'category_id',      
        'refTableClass'     => 'Category', 'Image',
        'refColumns'        => 'image_id' , 'category_id',      
        'Artist' => array(
        'columns'           => 'artist_id',      
        'refTableClass'     => 'Image',  
        'refColumns'        => 'image_id'    



Is the right way to join tables in zend???




Link to post
Share on other sites

I agree with that try Doctrine (or Propel) you might get addicted.

I think I read one of 448191's blog articles that coverd this exact subject.



Other then that I think your db design could use some work.

For example why not have a foreign key in your image table instead of joining artist_id with image_id?


Link to post
Share on other sites

I think you should redesign your database. You can easily eliminate the two category_cross tables. Just add a foreign key in the artist and image tables as someone suggested. Actually you need 3  master tables - Artist, Image and Category. One cross table where you associate artists with images. Add category id just to image master table. Also I would keep image urls should in images because an artist will have multiple images.

Link to post
Share on other sites
  • 3 weeks later...


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

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