etrepat / baum

Baum is an implementation of the Nested Set pattern for Laravel's Eloquent ORM.
http://etrepat.com/baum
MIT License
2.24k stars 459 forks source link

buildTree() with Laravel relations - using dimsav translation #121

Open aureliusm opened 10 years ago

aureliusm commented 10 years ago

Hi,

I am using baum on Page model (pages table) and dimsav Laravel Translations and have a problem, because I have a child table (page_translations) which has a foreign key in (pages.id). If I try to buildTree() with data including translations I get error "type":"ErrorException","message":"preg_replace(): Parameter mismatch, pattern is a string while replacement is an array","file":"C:\wamp\www\aurelius_angular\vendor\laravel\framework\src\Illuminate\Support\helpers.php","line":885

If I try to buildTree without translations, it works.

Thanks!

broszies commented 9 years ago

Hi, am trying to do exactly the same. Baum has an issue with this, which you can read about here; https://github.com/dimsav/laravel-translatable/issues/25. Looks like Baum saves the data before the translations can be handed over. You probably saw that yoursef - did you ever find a solution to this?

etrepat commented 9 years ago

Sorry for the late reply.

There's no bug/issue in Baum. This package just happens to hook on save events and perform several actions. Maybe we can find a way to make the packages compatible... What should be done differently for translatable to work?

broszies commented 9 years ago

thanks for getting back on this. I was rephrasing freekmurze calling it a "problem", no offense intended.

Freekmurzes fix (implement a service that calls up the translator before the saving event) from the same thread workes fine for me. It is, of course, a hack, My lack of skills regarding PHP preclude me from making any suggestions on how to find a better solution, though.

Again, thanks for your replies and work!

etrepat commented 9 years ago

No worries. No offense taken ;).

It is indeed a problem, but it's just not a bug on neither package side. We just handle "saves" differently and Baum happens to freshen the model instance after saving so it keeps the Nested Set indices current (because the update operation when moving, operates on SQL level) and, because of that, there's nothing for translatable to save.

I've commented on this issue on the translatable project as well: dimsav/laravel-translatable#25. Maybe I can think of something to make the packages compatible.