Not able to pull associated data

I set up a whole bunch of similar (but different) belongsTo relationships in my Items Table, which reference color names from a colors table (in order to get hex values corresponding to those names back). The name column in the colors table has a Unique index on it.

Basically, each item uses several colors from an established palette and I want to select from and display those colors on my page according to their name.

$this->belongsTo('Color1', [
        'className' => 'Colors',
        'foreignKey' => 'color_1',
        'bindingKey' => 'name',
        'propertyName' => 'Color1'
]
);
$this->belongsTo('Color2', [
        'className' => 'Colors',
        'foreignKey' => 'color_2',
        'bindingKey' => 'name',
        'propertyName' => 'Color2'
]
);
$this->belongsTo('Color3', [
        'className' => 'Colors',
        'foreignKey' => 'color_3',
        'bindingKey' => 'name',
        'propertyName' => 'Color3'
]
);

Then, in my controller, I have

$items = $this->Item->findByUName($uname, [
    'contain' => ['Color1','Color2','Color3']
])->first();

I’m not sure what I’m doing wrong, but the contain never happens and I’m not getting any errors. I get all my Item data, as well as the color names that are encoded in the associated Item columns… but the SQL log shows no joins, and there are no hex values or anything else coming back.

I think I may be answering my own question… just realized the docs seem to say you can’t use contain with findBy… hm

EDIT:

Well, I tried following the instructions under Custom Finder Methods (http://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#custom-finder-methods) but once again am finding the documentation seems to be missing critical info or more complete examples :frowning:

After some fiddling, I was able to get a custom finder method working with contain. I’m not sure I get what the advantage of having a custom finder method is vs just building the same query in the controller. I mean, I get it can be reused elsewhere with extra options as needed. Is that really that compelling? I guess so since I’m keeping it. Lol.

One tangential question, I haven’t yet found an answer in the docs:

Is there a way to select all the fields from one table but only one field from a related lookup table? And does Cake 3 offer a way to "collapse"the associated value so it becomes a property of the first table instead of a whole attached object?