Many_Many Issue (Column Ambiguous)

Hey guys,

I’ve looked everywhere for a solution to my problem with MANY_MANY but I just haven’t been successful.

So here’s the deal (3 table):



NichesOffers (niche_id, offer_id)

Relation (Offers.php):

‘niches_offers’=>array(self::MANY_MANY, ‘Niches’,

			'niches_offers(offer_id, niche_id)'),

And on NichesOffers.php I have two relations

		'offer' => array(self::BELONGS_TO, 'Offers', 'offer_id'),

		'niche' => array(self::BELONGS_TO, 'Niches', 'niche_id'),

So what I’m trying to do is look up a niche_id and return all offers that match:

$niche_id = 3;

	$criteria=new CDbCriteria;

	$criteria->with = array('niches_offers' => array('condition'=>'niche_id = :id', 'params'=>array(':id'=>$niche_id)));

	$criteria->together = true;

	$offers =new CActiveDataProvider('Offers', array('criteria'=>$criteria));

Here’s the error I’m getting:

CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column ‘published’ in where clause is ambiguous. The SQL statement executed was: SELECT t.title AS t0_c1, t.our_price AS t0_c12, t.regular_price AS t0_c13, AS t0_c0, AS t1_c0, AS t1_c1, niches_offers.published AS t1_c2, niches_offers.site_id AS t1_c3, niches_offers.created AS t1_c4, niches_offers.updated AS t1_c5 FROM offers t LEFT OUTER JOIN niches_offers niches_offers_niches_offers ON ( LEFT OUTER JOIN niches niches_offers ON ( WHERE ((published = 1) AND (site_id=1)) AND (niche_id = :id) LIMIT 10

I do have tables with the same column name (published) but I don’t see why this is happening.

Thanks so much for taking the time to check this out. Any advice is super appreciated.

Nevermind. Had a beforeFind that was setting everything without an alias. All fixed :)