Hello, I have been looking for a way to read data from 2 DBs using a second model in the read_data action, sadly when I print a debug I only get the output from the first model... there's no such thing as a faq or even a mention in the cf6 manual so could anyone please point me in the right direction?
pretty please?
Hi Crams,
Sorry, I don't understand what the problem is exactly :-(
You should be able to use two Read Data actions in the same form with no problems.
Bob
Yep it's a whole lot of trial and error Crams, the documentation is pretty sparse sometimes.
Let's say you have the following table structure.
users
id (primary key)
name
articles
author_id <-- obviously this is the user id of the author
content
In your read data action, the first model we shall call user and the second model we shall call article
Set the first to retrieve all entries (or first matching if you need)
In the second model, set "related to" to "user", relation to "One matching record, foreign key at the related table" (this should be set to whichever is the "main" table being referenced in the relation)
In foreign key enter "id" or if necessary in the relation conditions enter "user.id:article.author_id"
NOW. You can either leave it how it is, or under the first model in Fields to Retrieve you can for example do:
user.id
user.name
article.author_id
Or to get a bit more complicated you can do
model.field:model.alias
I'm sorry I was really sleepy when I wrote the first message hehehehe.... What I meant is that I'm trying to retrieve data from two tables in the same DB, Healy's answer works perfect!! many thanks to you both guys!!!