BELONGS_To Relation without primary key

Hello,

I have a model PartOrder which belongs to a Customer model.

Both tables have the field customerNbr, but customerNbr is not the primary key in the Customer table, as it contains characters and I haven’t figured out how the url mamager works with non-integer primary keys.

So therefore I need to build a BELONGS_TO ‘customer’ relation in the PartOrder model.

How can I specify the ‘customer’ relation in the ‘PartOrder’ model to get built something like ‘FROM PartOrder t LEFT JOIN Customer customer on t.customerNbr=customer.customerNbr’?

Thanks in advance.

Best regards,

Joachim

Something like this (from top of my memory)




customer = array(self::BELONGS_TO, Customer, '', 'on'=>'...');



/Tommy

This doesn’t work.

The guide says that the on clause will be appended to the joining condition.

Try it! You may have to use together for the table alias to be recognized.

/Tommy


            	'page/<slug:[a-z0-9-]+>'=>'page/view',

            	'<controller:\w+>/<id:\d+>' => '<controller>/view',



The first line works for me.

But I believe that you can swap <id:\d+> in the second line with <id:[a-z0-9]+> - I haven’t actually tried it (yet). :)

Thanks Man,

IT’s Solved My Problem, Great Trick :)

Only this works for me:


'relation' => array(self::BELONGS_TO, 'MainModel', '', 'foreignKey' => array('field'=>'field'),

1 Like