Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8879037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:51:34+00:00 2026-06-14T19:51:34+00:00

I am using Datamapper and want to join all columns of a related table

  • 0

I am using Datamapper and want to join all columns of a related table (1:1 relationship) in the result set. Hence, my code reads as follows:

$p = new Project();
$arrAll = $p->where("id <", 100)->where_related('outboundform', 'reference_type', 'project')->include_related('outboundform')->get()->all_to_array();
print_r($arrAll);

The query works, but no column of table ‘outboundform’ shows up in the result, they get completely ignored!! I just checked and the generated SQL reads:

SELECT `project` . * , `outboundform`.`id` AS outboundform_id, `outboundform`.`reference_type` AS outboundform_reference_type, `outboundform`.`reference_id` AS outboundform_reference_id, `outboundform`.`created` AS outboundform_created, `outboundform`.`updated` AS outboundform_updated, `outboundform`.`v1` AS outboundform_v1, `outboundform`.`v2` AS outboundform_v2, `outboundform`.`v3` AS outboundform_v3, `outboundform`.`v4` AS outboundform_v4, `outboundform`.`v5` AS outboundform_v5 FROM (`project`) LEFT OUTER JOIN `outboundform` outboundform ON `project`.`id` = `outboundform`.`reference_id` WHERE `project`.`id` <100 AND `outboundform`.`reference_type` = 'project' LIMIT 0 , 30

which is OK and gives me the correct result when executed.
What’s Datamappers problem here? Why is it not return the full amount of columns?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:51:37+00:00Added an answer on June 14, 2026 at 7:51 pm

    The related outboundform row’s properties should be accessible in the result object prefixed with the relation’s name. So the id becomes outboundform_id, the reference_type becomes outboundform_reference_type and so on.

    The problem is that all_to_array() doesn’t transfer those to the array version of results.
    If you want to include them you will have to explicitly list them:

    $arrAll = $p->/* snip */->all_to_array(array('id', 'name', 'outboundform_id', 'outboundform_reference_type')); // Project fields and outboundform fields too
    

    If you have an instance of any model, you can get the list of fields by the $instance->fields property of that model (from the database table), and use those to create the list for the all_to_array call by creating prefixed names for the included relation.

    Alternatively, if you only need the [] way of accessing fields, you can implement ArrayAccess interface like this:

    class DataMapper2 extends DataMapper implements ArrayAccess
    { 
        public function offsetSet($offset, $value)
        {
            if (is_null($offset)) {
                throw new ErrorException('model instances doesn\'t support pushing new fields');
            } else {
                $this->{$offset} = $value;
            }
        }
        public function offsetExists($offset)
        {
            return isset($this->{$offset});
        }
        public function offsetUnset($offset)
        {
            unset($this->{$offset});
        }
        public function offsetGet($offset)
        {
            return isset($this->{$offset}) ? $this->{$offset} : null;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just using DataMapper for the first time. I have set up a table in
Using a populated Table Type as the source for a TSQL-Merge. I want to
I'm testing a Sinatra application, which is using DataMapper, with RSpec. The following code:
I'm using datamapper to store a lot of nokogiri-scraped data to rows This set
I want to show flash messages using sinatra-redirect-with-flash gem. Here's my ruby code: require
I'm using DataMapper in a Rails project, and have found that calling to_json on
I have found several examples using datamapper and was able to get them to
Hello I am trying to setup a Padrino project using DataMapper and MySQL on
See the full error here: http://notesapp.heroku.com/ I'm using DataMapper and dm-validations 0.10.2. No matter
I’m setting up relationships in my models using DataMapper but I’ve hit a wall.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.