Yii Framework Forum: Alternative to findAllBySql() for many_many relation - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Alternative to findAllBySql() for many_many relation HAS_MANY through requires a model , correct? Rate Topic: -----

#1 User is offline   windsor 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 04-October 11
  • Location:Tampa, FL

Posted 06 November 2011 - 10:11 PM

Here's a new twist on an old chestnut.... looking for any advice or guidance on what is the Yii way to handle this scenario:

I have the following relationship in the database:

tbl_account-> PK id
tbl_invoice -> PK id
tbl_payment -> PK id
tbl_account_invoices_payments PK (account_id, invoice_id, payment_id)

I have models for Account, Invoice, Payment but not for tbl_account_invoice_payment.

Right now in the Invoice model I have this code to return all the invoice objects that match to a specific account_id and payment_id:


$sql = "SELECT invoice_id FROM tbl_account_invoice_payment WHERE account_id=':accountId 'AND payment_id=':paymentId'";

$params=array(':accountId'=>$account->id,':paymentId'=>$payment->id);
return self::model()->findAllBySql($sql, $params);



I dont think this will work, and it feels so....well...dirty! :unsure: is there a better way?
How can I get a set of filtered invoice objects back from the return value?

(I like the idea of setting up a HAS_MANY , through relationship in the model, but dont need the overhead of another model class for the relational table.)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users