Support the ongoing development of Laravel.io →
Database Eloquent

I get the message "depth too great" when querying a couple of relations.

These are my models:

class TwitterStatus extends Eloquent {

	protected $table = 'twitter_statuses';
	
	protected $softDelete = true;
	
	protected $guarded = array('id');
	
	public function twitterRetweet() {
        return $this->hasMany('TwitterRetweet');
    }
	
	public function twitterReply() {
        return $this->hasMany('TwitterReply');
    }
	
	public function twitterTag() {
        return $this->hasMany('TwitterTag');
    }
	
	public function twitterUser() {
        return $this->belongsTo('TwitterUser');
    }
	
}
class TwitterTag extends Eloquent {

	protected $table = 'twitter_tags';
	
	protected $softDelete = true;
	
	protected $guarded = array('id');
	
	public function twitterStatus() {
        return $this->belongsTo('TwitterStatus');
    }
	
	public function tag() {
        return $this->belongsTo('Tag');
    }
	
	public function user() {
        return $this->belongsTo('Users');
    }
}

And this is the query

// Get the status information
$statuses = TwitterStatus::select('id','datetime','text','twitter_user_id')
	->with(array('twitterTag' => function($query) {
		//$query->select('tag_id');
	}))
	->with(array('twitterUser' => function($query) {
		$query->select('id','screen_name');
	}));

// Loop through the random ids
$statuses = $statuses->where(function($query) use ($twitter_status_ids) {
	foreach($twitter_status_ids as $id) 
	{
		$query->orWhere('twitter_statuses.id','=',$id);//17243
	}
});
$statuses = $statuses->get();

The query results in the following

object Illuminate\Database\Eloquent\Collection (1) {
    protected items -> array(1) [
        object TwitterStatus (20) {
            protected table -> string (16) "twitter_statuses"
            protected softDelete -> bool TRUE
            protected guarded -> array(1) [
                string (2) "id"
            ]
            protected connection -> NULL
            protected primaryKey -> string (2) "id"
            protected perPage -> integer 15
            public incrementing -> bool TRUE
            public timestamps -> bool TRUE
            protected attributes -> array(4) [
                'id' => string (5) "17243"
                'datetime' => string (19) "2013-11-02 11:06:32"
                'text' => string (74) "RT @vvdburen: Onze #lijst voor de #GR2014 http://t.co/nDE6TuCvcL #VVDBuren"
                'twitter_user_id' => string (4) "3994"
            ]
            protected original -> array(4) [
                'id' => string (5) "17243"
                'datetime' => string (19) "2013-11-02 11:06:32"
                'text' => string (74) "RT @vvdburen: Onze #lijst voor de #GR2014 http://t.co/nDE6TuCvcL #VVDBuren"
                'twitter_user_id' => string (4) "3994"
            ]
            protected relations -> array(2) [
                'twitterTag' => object Illuminate\Database\Eloquent\Collection (1) {
                    protected items -> array(1) [
                        object TwitterTag (20) {
                            protected table -> string (12) "twitter_tags"
                            protected softDelete -> bool TRUE
                            protected guarded -> array(1) [
                                *depth too great*
                            ]
                            protected connection -> NULL
                            protected primaryKey -> string (2) "id"
                            protected perPage -> integer 15
                            public incrementing -> bool TRUE
                            public timestamps -> bool TRUE
                            protected attributes -> array(7) [
                                *depth too great*
                            ]
                            protected original -> array(7) [
                                *depth too great*
                            ]
                            protected relations -> array()
                            protected hidden -> array()
                            protected visible -> array()
                            protected appends -> array()
                            protected fillable -> array()
                            protected dates -> array()
                            protected touches -> array()
                            protected observables -> array()
                            protected with -> array()
                            public exists -> bool TRUE
                        }
                    ]
                }
                'twitterUser' => object TwitterUser (20) {
                    protected table -> string (13) "twitter_users"
                    protected softDelete -> bool TRUE
                    protected guarded -> array(1) [
                        string (2) "id"
                    ]
                    protected connection -> NULL
                    protected primaryKey -> string (2) "id"
                    protected perPage -> integer 15
                    public incrementing -> bool TRUE
                    public timestamps -> bool TRUE
                    protected attributes -> array(2) [
                        'id' => string (4) "3994"
                        'screen_name' => string (15) "HansvanVierssen"
                    ]
                    protected original -> array(2) [
                        'id' => string (4) "3994"
                        'screen_name' => string (15) "HansvanVierssen"
                    ]
                    protected relations -> array()
                    protected hidden -> array()
                    protected visible -> array()
                    protected appends -> array()
                    protected fillable -> array()
                    protected dates -> array()
                    protected touches -> array()
                    protected observables -> array()
                    protected with -> array()
                    public exists -> bool TRUE
                }
            ]
            protected hidden -> array()
            protected visible -> array()
            protected appends -> array()
            protected fillable -> array()
            protected dates -> array()
            protected touches -> array()
            protected observables -> array()
            protected with -> array()
            public exists -> bool TRUE
        }
    ]

As you can see in stead of displaying the twitterTags data I get the message depth to great. Does anyone know why this is and what I did wrong?

BTW, when I uncomment //$query->select('tag_id'); the response is array() in stead of dept to great

Last updated 3 years ago.
0

Are you sure it's not a dump-only problem?

Last updated 3 years ago.
0

Damn you are right!

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.