We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

EE 3.1 DP: When a model is given a ->fields() directive it only retrieves one result.

Developer Preview

Greg Ferrell's avatar
Greg Ferrell
102 posts
10 years ago
Greg Ferrell's avatar Greg Ferrell

In EE 3.0, if you used something like this:

$result = ee('Model')->get('ModelName')->fields('myColumn')->all();

You would get all results with just the myColumn field set.

In ee 3.1 if you use ->fields() on a model it will only return one result no matter what limit you set or how else you retrieve the data.

Removing ->fields() and leaving every other filter or limit directive on a model gets the desired results.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

Hmm I’m unable to reproduce, Greg. We’re using fields() a lot, too, so I suspect it would have broken a lot if that’s all it took to reproduce. Are you seeing this with one of our native models?

       
Greg Ferrell's avatar
Greg Ferrell
102 posts
10 years ago
Greg Ferrell's avatar Greg Ferrell

We are using them with multiple addons, multiple devs and multiple EE 3.1 installs.

It is our models, but we are using the model interface laid out in the docs and it worked in EE 3.0:

class Group extends Model
{
 protected static $_primary_key = 'tag_group_id';
 protected static $_table_name = 'tag_groups';

 protected $tag_group_id;
 protected $tag_group_name;
 protected $tag_group_short_name;
}
//END Group
       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

I’m not sure what to recommend, I can’t reproduce with models in an add-on either. Does it still do it if you try to access something like ChannelEntry?

       
Greg Ferrell's avatar
Greg Ferrell
102 posts
10 years ago
Greg Ferrell's avatar Greg Ferrell

I did it using the member model (since it extends Model and ChannelEntry does not) and the bug persists. It’s only when its not the primary key in the ->fields()

This produces 1 result:

ee('Model')->get('Member')->fields('screen_name')->all()->getDictionary('screen_name', 'screen_name');

This produces many:

ee('Model')->get('Member')->all()->getDictionary('screen_name', 'screen_name');
       
Greg Ferrell's avatar
Greg Ferrell
102 posts
10 years ago
Greg Ferrell's avatar Greg Ferrell

I should add for whatever reason, if the ->fields() contains the primary key, it works as expected.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

Thanks, Greg! That’s the ticket. I’ve tracked down the problem and put in a fix, should be working correctly in the next build.

       
Greg Ferrell's avatar
Greg Ferrell
102 posts
10 years ago
Greg Ferrell's avatar Greg Ferrell

Great news. Thanks!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.