Hi Anch,

Here are some of the things within the Model class which you can
override that may help:

        var $useTable = null;
        var $displayField = null;
        var $primaryKey = null;

1. $primaryKey variable will allow you to override the column used as
the primary key.

2. Yes you need specify the details in your associations

For instance in your Article Model:

        var $hasAndBelongsToMany = array(
                        'Users' =>
                                array('className' => 'Users',
                                                'joinTable' => 'user_articles',
                                                'foreignKey' => 'article_id',
                                                'associationForeignKey' => 
'user_id',
                                                'conditions' => '',
                                                'fields' => '',
                                                'order' => '',
                                                'limit' => '',
                                                'offset' => '',
                                                'unique' => '',
                                                'finderQuery' => '',
                                                'deleteQuery' => '',
                                                'insertQuery' => ''
                                ),

        );

I left in the other fields you can specify for completeness sake.

Also if the other field is a auto increment field you can ignore it it
should just by populated by the database.

Cheers,

Coder

On Aug 21, 9:30 am, anch <[EMAIL PROTECTED]> wrote:
> Hi, I am building a CakePHP-based application using all the database
> tables built by another application. However, the database tables
> related to models are defined differently from CakePHP's convention.
>
> We have the following tables: articles, users, ratings for the models:
> Article, User, and Rating; the associations among them include the
> following, "Article hasOne Rating" and "User hasAndBelongsToMany
> Article"
>
> I have the following questions:
>
> 1. In the articles table, article_id was used as the column name for
> the article id (the primary key). When I try to access ratings records
> associated with Article, it generated the following error:
>
> SQL Error: 1054: Unknown column 'Article.id' in 'on clause' in /var/
> www/html/cake/cake/libs/model/datasources/dbo_source.php on line 463
>
> I guess CakePHP was expecting the column name to be 'id' in the
> articles table. If so, can I work around this problem without changing
> the column name?
>
> 2. The join table was named as user_articles. According to CakePHP
> convention, it should be articles_users. Is there anyway I can
> override the CakePHP convention to use user_articles instead? Also
> there was an extra field for record id (thus it has three columns: id,
> article_id, user_id), can we live with this?
>
> Could anybody help me to resolve the above issues to override the
> CakePHP convention? Thanks a lot.
>
> Best regards,
> Anch


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to