<p>Just have your plugin supply a custom <code>MyPluginEntryModel</code> that extends Craft's <code>EntryModel</code> and merges in any custom attribute definitions from your custom table.</p>

<pre><code>class MyPluginEntryModel extends EntryModel
{
   ....

    protected function defineAttributes()
    {
        return array_merge(parent::defineAttributes(), array(
            'customAttribute1' =&gt; AttributeType::Number,
            'customAttribute2' =&gt; AttributeType::String,
        ));
    }

   ....
}
</code></pre>

CC BY-SA 3.0
2015-01-09T04:03:47.500Z
Then how do I populate the model with both the entry and custom data?
a-am
CC BY-SA 3.0
2015-01-09T04:13:28.637Z
I think this should work?
$outputModel = MyPluginEntryModel::populateModel($entry,$tablerecord);
a-am
CC BY-SA 3.0
2015-01-09T04:54:32.833Z
That doesn't seem to work. My goal would be to return a model instead of an array of models.
a-am
CC BY-SA 3.0
2015-01-09T05:42:31.230Z
You'll need to post the code you're using in the original question. Can't tell what's going on otherwise.
Brad Bell
CC BY-SA 3.0
2015-01-09T05:50:19.890Z
I got that to work just now. How do I return a model to the front end instead of an array of models?
a-am
CC BY-SA 3.0
2015-01-09T05:53:16.540Z
`$arrayOfModels[0]`? Really hard to tell without your code and some context into what's happening.
Brad Bell
CC BY-SA 3.0
2015-01-09T05:55:18.473Z
Thanks Brad I guess I don't know the question to ask.
a-am
CC BY-SA 3.0
2015-01-09T05:56:19.150Z
You and me both. :)
Brad Bell
CC BY-SA 3.0
2015-01-09T03:55:21.007Z
2015-01-09T03:55:21.007Z
Brad Bell
<p>In a plugin I am returning entries from a section. Can I combine a returned entry from that section with data from a custom table into one model for output?</p>

<plugin-development><entrymodel>
In plugin combine a returned entry with custom table data
# In plugin combine a returned entry with custom table data

(Asked by: username_0 on 2015-01-09)

In a plugin I am returning entries from a section. Can I combine a returned entry from that section with data from a custom table into one model for output?

**Tags:** plugin-development, entrymodel


---

## 1 answers

### Answer by username_1 on 2015-01-09. Score: 1 | Accepted answer

Just have your plugin supply a custom MyPluginEntryModel that extends Craft's EntryModel and merges in any custom attribute definitions from your custom table.
class MyPluginEntryModel extends EntryModel
{
   ....

    protected function defineAttributes()
    {
        return array_merge(parent::defineAttributes(), array(
            'customAttribute1' => AttributeType::Number,
            'customAttribute2' => AttributeType::String,
        ));
    }

   ....
}

> **Comments:**
> **username_0**: Then how do I populate the model with both the entry and custom data?  
> **username_0**: I think this should work? $outputModel = MyPluginEntryModel::populateModel($entry,$tablerecord);  
> **username_0**: That doesn't seem to work. My goal would be to return a model instead of an array of models.  
> **username_1**: You'll need to post the code you're using in the original question. Can't tell what's going on otherwise.  
> **username_0**: I got that to work just now. How do I return a model to the front end instead of an array of models?  
> **username_1**: `$arrayOfModels[0]`? Really hard to tell without your code and some context into what's happening.  
> **username_0**: Thanks Brad I guess I don't know the question to ask.  
> **username_1**: You and me both. :)  

---

