Jump to content

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


littlevisuals

Recommended Posts

Hi everyone,

 

I have a database with the looks like the following;

 

owBD9.png

 

I have created the model below

 

<?php
/**
* 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 comment
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 comment
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 comment
Share on other sites

  • 3 weeks later...
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.