Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CActiveRecord relations 'on' option does not add to join parameters #261

Closed
qiangxue opened this issue Feb 15, 2012 · 1 comment
Closed

Comments

@qiangxue
Copy link
Member

What steps will reproduce the problem?

  1. Create the following MYSQL tables/views
    --TABLE: commissions--
    id->PRIMARY KEY
    date_added
    order_id->INDEX
    salesrep_id->INDEX
    customer_id->INDEX
    commission_total
    status
    --VIEW: rep_view_customer--
    entity_id
    email
    first_name
    last_name
    company
  2. Create model for the table and the view.
  3. In the Commissions model create the following relation:
    'rep_view_customer' => array(self::HAS_ONE, 'RepViewCustomer', '', 'on'=>'rep_view_customer.entity_id = t.customer_id'),
  4. In a view file(in CGridView) add the following column: 'rep_view_customer.first_name'
  5. In RepViewCustomer set custom primary key:
    public function primaryKey(){
    return 'entity_id';
    }

What is the expected output? What do you see instead?
You would think this would simply bring up the first name from the related row in the rep_view_customer View. It Does Not.
I get the following error:

CDbException

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 't.customer_id' in 'where clause'. The SQL statement executed was: SELECT rep_view_customer.entity_id AS t1_c0, rep_view_customer.email AS t1_c1, rep_view_customer.first_name AS t1_c2, rep_view_customer.last_name AS t1_c3, rep_view_customer.company AS t1_c4 FROM rep_view_customer rep_view_customer WHERE (rep_view_customer.entity_id = t.customer_id)

Why would it have rep_view_customer twice in the from field?
if i do the following in my relation: 'rep_view_customer' => array(self::HAS_ONE, 'RepViewCustomer', '', 'on'=>'rep_view_customer.entity_id = 56') then i'll get a first name. but this is not correct.

What version of the product are you using? On what operating system?
Apache/2.2.21 (Fedora) Yii Framework/1.1.8

Please provide any additional information below.
I simply want to relate to another model by something other than a primary key.

Migrated from http://code.google.com/p/yii/issues/detail?id=3028


earlier comments

qiang.xue said, at 2012-01-01T03:37:10.000Z:

set for 1.1.10 milestone

qiang.xue said, at 2012-01-01T03:37:36.000Z:

set for 1.1.10 milestone

@3000
Copy link

3000 commented May 7, 2012

Just adding a vote for this one

@samdark samdark closed this as completed Nov 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants