Question

how to get name of (UserTransactionType.name) with Transaction.who_pay_fee_1,2,3 fields.

'user_transaction_type_id' works well but how to get the rest of fields work :(

//Transaction Model
        public $belongsTo = array(
                'UserTransactionType' => array(
                    'className' => 'UserTransactionType',
                    'foreignKey' => 'user_transaction_type_id',
                    'conditions' => '',
                    'fields' => '',
                    'order' => ''
                ),

//UserTransactionType Model
public $hasMany = array(
        'Transaction' => array(
            'className' => 'Transaction',
            'foreignKey' => 'user_transaction_type_id',
            'dependent' => false,
))

enter image description here

Was it helpful?

Solution 2

For people they like CakePhp :)
in Controller ->
get the list of 'UserTransactionType'
in View ->
after looping trough all the transactions; in Transaction Status column simply load the 'UserTransactionType'array and assign the number of array to $userTransactionTypes.

$userTransactionTypes[$transaction['Who_pay_fee_1']];

To be honest it was straight forward but needed a bit concentration :)

OTHER TIPS

This is the sample code for your controller:

$this->UserTransactionType->find('all',array(
                                             'fields' => array('name'),
                                             'contain' => array('Transaction')
                                            )
                                 );

If Models are associated you can specify in 'contain' which of them you want to get in the result.

If you want to have only some fields of related Model, you can determine them after 'Transaction' in 'contain' just like in the regular find() query:

'contain' => array('Transaction' => array('fields' => array('field_1',
                                                            'field_2') ))  

But in your case, you don't need to specify fields, because by default you get all fields.

So no matter if you define or not fields "who_pay_fee_1,2,3" because if you use 'contain' by default you will get foreing_key - user_transaction_type_id.

I hope it's helpful

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top