<p>Not 100% sure I'm following what you're looking for, but if you have a <code>UserRecord</code> defined with a <code>phone</code> relation, then something like this should do what you want:</p>

<pre><code>$phone = UserRecord::model()-&gt;with('phone')-&gt;findById(1)-&gt;phone;
</code></pre>

CC BY-SA 3.0
2015-04-30T04:27:44.243Z
I suppose that will do, I was trying to find a way to somewhat automate it but it might just be overkill. What would be the syntax to call an extra relation? 
```$phone = UserRecord::model()->with('phone, age')->findById(1)->phone;```
Dale Inverarity
CC BY-SA 3.0
2015-04-30T06:00:06.190Z
Got it. ```$phone = UserRecord::model()->with('phone', 'age')->findById(1)->phone;```
Dale Inverarity
CC BY-SA 3.0
2015-04-30T04:01:32.027Z
2015-04-30T04:01:32.027Z
Brad Bell
<p>This post may scream ignorance (Still delving into the plugin world). I'm coming from a background using mostly laravel for PHP application development and building a few plugins now on Craft has felt a bit verbose to access related objects. Is there any "nice" way to allow something like the following in Craft?</p>

<pre><code>$phone = User::find(1)-&gt;phone;
</code></pre>

<p>or in terms of craft plugins, just include related data in the model itself instead of having dozens of findXbyId methods littering the code?</p>

<p>related: <a href="https://craftcms.stackexchange.com/questions/7077/populatemodel-usage-with-eager-loading-related-records">populateModel usage with eager loading related records</a></p>

<p>Any generic solutions?</p>

<p>Thanks!</p>

<plugin-development>
Possible to Directly access related records (Laravel ORM style)?
# Possible to Directly access related records (Laravel ORM style)?

(Asked by: username_0 on 2015-04-29)

This post may scream ignorance (Still delving into the plugin world). I'm coming from a background using mostly laravel for PHP application development and building a few plugins now on Craft has felt a bit verbose to access related objects. Is there any "nice" way to allow something like the following in Craft?
$phone = User::find(1)->phone;

or in terms of craft plugins, just include related data in the model itself instead of having dozens of findXbyId methods littering the code?
related: populateModel usage with eager loading related records
Any generic solutions?
Thanks!

**Tags:** plugin-development


---

## 1 answers

### Answer by username_1 on 2015-04-30. Score: 0 | Accepted answer

Not 100% sure I'm following what you're looking for, but if you have a UserRecord defined with a phone relation, then something like this should do what you want:
$phone = UserRecord::model()->with('phone')->findById(1)->phone;

> **Comments:**
> **username_0**: I suppose that will do, I was trying to find a way to somewhat automate it but it might just be overkill. What would be the syntax to call an extra relation?  ```$phone = UserRecord::model()->with('phone, age')->findById(1)->phone;```  
> **username_0**: Got it. ```$phone = UserRecord::model()->with('phone', 'age')->findById(1)->phone;```  

---

