corcel / acf

Advanced Custom Fields (ACF) plugin for Corcel
128 stars 100 forks source link

BasicField -> fetchFieldType fails for repeater field #3

Closed lasmanis closed 7 years ago

lasmanis commented 7 years ago

I'm trying to access a repeater field like so:

$this->acf->repeater('field_name');

Where $this is an instance of a Model that is a child of Corcel\Post through 2 levels of inheritance. My Model overrides protected $postType = 'my_post_type';.

By using this code I'm getting an error in line 113 of the BasicField class.

Particularly, $post is null.

I tried changing the line $post = $this->post->where('post_name', $fieldKey)->first(); to $post = Post::where('post_name', $fieldKey)->first(); and that seem to work. It seems like $this->post is adding a post_type restriction to the SQL query that's being executed.

I would appreciate to hear your thoughts on this.

Edit:

I'm actually having the same issue anywhere the $post variable is being used to perform a query. For instance, line 52 of File.php ($post->find($value); doesn't work, Post::find($value); does). So this is an issue not just related to the repeater field.

Regards, Leonidas

Charl13 commented 7 years ago

I'm experience the same issue.

jgrossi commented 7 years ago

Hi @lasmanis and @Charl13 thanks for reporting. Can you send a PR request fixing those issues? Please make sure all unit tests are passing and maybe if possible write a new one that tests this particular behavior. I guess I will not have enough time until the next week to do that, sorry about that. If you can, please send a PR :D

jgrossi commented 7 years ago

I fixed the database connection issue, maybe this fix the problem you were experiencing. JG