Forums

HOw do I reference a second model?

NickOg 25 Jan, 2015
Hi,

I have a model 'mdlMbrReceipts' and I can reference the data there with the usual {mdlMbrReceipts.idReceipt}.

If I add a second model 'mdlUniqueReceivers' - how do I reference that data? I presumed using the same syntax {mdlUniqueReceivers.payReceivedBy} but that doesn't work.
Should I be able to see the SELECT for that second model with debug? I can't

Puzzled!

Nick..
Szczypka 26 Jan, 2015
Hi Nick,
1. Add new model
2. Choose the right table in Table name
3. Relation: belongsTo
Foreign key: add the key from your main model here
Primary key: add the key from the new model here

Now try the connection.
Max_admin 26 Jan, 2015
Hi Nick,

Yes, that syntax should work, and you should be able to see the new model in the debug if its enabled.

If the relation is "hasOne" or "belongsTo" then the model will be used in a JOIN, but it will be a new select if its of type "hasMany".

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
NickOg 26 Jan, 2015
Hi Max & Szczypka,

There is no relationship between the two tables. I planned to use the second to build a look up to build a drop-down as a filter for the first table. So that step 3 in Szczypka's suggestion doesn't apply. I can try that but then I will presumably need to then filter out duplicates. I have got round it OK by adding a db read for the look-up in the header.

Regards
Nick
Max_admin 27 Jan, 2015
Hi Nick,

Well, if there is no relation to the main model then the new model data will not be available, I think its ok to use a "db read" in this case!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
This topic is locked and no more replies can be posted.