Open blackgearit opened 8 years ago
Hi blackgearit, I want to ask if you (anyone?) found a workaround for this?
I hit exactly this error with a very similar query.
thanks
l.
so I found something that seems to work:
By overriding scopeWithoutNode func to include the table name with the PK.
public function scopeWithoutNode($query, $node)
{
return $query->where($this->table . '.' . $node->getKeyName(), '<>', $node->getKey());
}
I dont know yet if there are relevant tests, OR more importantly - if this breaks anything else.
But in my limited testing it seems to do what I need, and it kinda makes sense. if anybody has any opinion or feedback on it please post.
Looking at the code around this also raises the question:
should there be a Node function to: "getQualifiedKeyColumnName()" ?
I'd be happy to submit a pr if its needed.
thanks
l.
In my Project I've referenced the model with baum in a hasToMany relation to another model for translations.
So, my Skills (baum) model hasMany SkillLocales
Eloquent raises this error when i use this to retrieve all Skills with locale
$skills = Skill::root()->descendants()->join('skills_locale','skills.id','=','skill_id')->where('skills_locale.locale',App::getLocale())->where('active',1)->get();
Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous (SQL: select * from
skills
inner joinskills_locale
onskills
.id
=skill_id
wherelft
>= 1 andlft
< 8 andid
!= 1 andskills_locale
.locale
= en andactive
= 1 order byskills
.lft
asc)solved modifying /vendor/baum/baum/src/Baum/Node.php Line 471
from return $query->where($node->getKeyName(), '!=', $node->getKey()); to return $query->where($node->getTable().'.'.$node->getKeyName(), '!=', $node->getKey());