You are missing a couple of key points to use DataMapper for CodeIgniter. First of all, you need to do some simple and important things. DataMapper (DM) uses the normalized db name to search for relationships. This means that if you request your dB. Now itβs a little harder to use DM for two columns, and I think you really don't need this.
First, if you are not using DM, you really only need two queries
SELECT u.*, m.* FROM messages AS m, users AS u WHERE m.from = u.id AND m.id = SOME_ID.
This request will provide you with all user information and message information for some message identifier. Now this is a semi-simple case, because I assume that a message can only be from one user.
For a field, on the other hand, I assume you should use a relational table. To use a DM for this, you should call the table something like users_messages
, but again why do you need to use the DM when it is really full.
Now for the from field, you have a many, many relationship, because a message can have many users to whom it is intended, and a user can have many messages that they sent.
So create a table like this
CREATE TABLE message_to ( user_id BIGINT UNSIGNED NOT NULL, message_to_id BIGING UNSIGNED NOT NULL, PRIMARY KEY (user_id, message_to_id), );
If you want to do it right, you will also use foreign keys, but it depends on your DB
Now you can request very easily and get all the users to whom the message was sent.
SELECT u.*, m.* FROM users AS u, m AS messages JOIN messages_to AS m_t ON (u.id = m_t.user_id)
And requesting another way is just as easy to get all the messages sent by the user.
Remember only that a tool like DM does not mean that it is the best tool for work and actually uses DM, in this case it incurs rather decent overhead when it is not necessary.
Doing this with DM will require the same thing that you simply cannot call your tables / columns as you see fit, and you need a class for each table, creating it with other tables.
Bearing in mind that you have a lot of extra work to use DM, you need to study their syntax.