# |
Nov 8th 2019, 12:31 |
dev.cyrusjayson |
here |
# |
Nov 8th 2019, 12:30 |
dev.cyrusjayson |
gave_fruits, sorry not in the screenshot |
# |
Nov 8th 2019, 12:29 |
frank |
@dev.cyrusjayson In which table is the user_id? |
# |
Nov 8th 2019, 12:24 |
dev.cyrusjayson |
this is the models |
# |
Nov 8th 2019, 12:22 |
dev.cyrusjayson |
following this is not helping https://book.cakephp.org/3/en/orm/retrieving-data-and-resultsets.html#passing-conditions-to-contain |
# |
Nov 8th 2019, 12:20 |
dev.cyrusjayson |
An Internal Server Error Occurred |
# |
Nov 8th 2019, 12:19 |
dev.cyrusjayson |
@frank I got internal error this is only thing is working but I want to filter the GaveFruits by user_id so I can get specific only ```$fruits = $this->Fruits->find('all') ->contain(['GaveFruits']);``` |
# |
Nov 8th 2019, 12:16 |
frank |
@dev.cyrusjayson Could you try `'GaveFruits' => function ….` instead of `'GaveFruits', function ….` (arrow vs comma) |
# |
Nov 8th 2019, 12:08 |
slackebot1 |
[CORE/src/ORM/EagerLoader.php, line 410]``` but if I remove the ->where([‘user_id’ => 1]) everything is working so I think the problem is in ->where but based on the documentation, I am fopllowing it correctly |
# |
Nov 8th 2019, 12:08 |
dev.cyrusjayson |
I have this query ``` $fruits = $this->Fruits->find('all') ->contain(['GaveFruits',function (Query $q){ return $q ->select(['id', 'name']) ->where(['user_id' => 1]); }]); ``` and I get this error ```Warning (2): Illegal offset type in isset or empty |
# |
Nov 8th 2019, 12:01 |
pieceof |
whoami |
# |
Nov 8th 2019, 11:01 |
dev.cyrusjayson |
@frank noted on that. thanks |
# |
Nov 8th 2019, 10:59 |
frank |
@dev.cyrusjayson You can remove the foreignKey from the association definition. As you’re following the conventions Cake will know to use user_id for Users. |
# |
Nov 8th 2019, 10:52 |
dev.cyrusjayson |
sorry. it all works. thanks mate. that fucking cache save the day |
# |
Nov 8th 2019, 10:45 |
graziel |
what do you mean not working? you get error or something? |
# |
Nov 8th 2019, 10:38 |
dev.cyrusjayson |
This works! thank you. ``` $this->paginate = [ 'contain' => ['Customers', 'Statuses', 'Users'] ]; $orders = $this->paginate($this->Orders); $this->set(compact('orders')); ``` but my association not working. see below ``` $this->belongsTo('Users', [ 'foreignKey' => 'user_id' ]); ``` |
# |
Nov 8th 2019, 10:34 |
dereuromark |
Going to release TinyAuth next generation auth plugin if someone wants to give early feedback before I release the major? Ideally the ones already using it and checking BC etc. |
# |
Nov 8th 2019, 10:31 |
dev.cyrusjayson |
ok |
# |
Nov 8th 2019, 10:31 |
graziel |
bin/cake orm_cache clear |
# |
Nov 8th 2019, 10:31 |
dev.cyrusjayson |
how? |
# |
Nov 8th 2019, 10:31 |
graziel |
try clearing orm cache |
# |
Nov 8th 2019, 10:31 |
dev.cyrusjayson |
do I need to compile something? |
# |
Nov 8th 2019, 10:30 |
dev.cyrusjayson |
what is going on. kinda frustrating |
# |
Nov 8th 2019, 10:30 |
dev.cyrusjayson |
even here I can’t see the user_id ``` $this->paginate = [ 'contain' => ['Customers', 'Statuses', 'Users'] ]; $orders = $this->paginate($this->Orders); $this->set(compact('orders')); ``` |
# |
Nov 8th 2019, 10:29 |
dev.cyrusjayson |
it is not a field. it is association in users model |
# |
Nov 8th 2019, 10:28 |
slackebot1 |
'foreignKey' => 'user_id' ]); $this->hasMany('Suborders', [ 'foreignKey' => 'order_id' ]); } ``` |
# |
Nov 8th 2019, 10:28 |
dev.cyrusjayson |
``` public function initialize(array $config) { parent::initialize($config); $this->setTable('orders'); $this->setDisplayField('id'); $this->setPrimaryKey('id'); $this->belongsTo('Customers', [ 'foreignKey' => 'customer_id' ]); $this->belongsTo('Statuses', [ 'foreignKey' => 'status_id' ]); $this->belongsTo('Users', [ |
# |
Nov 8th 2019, 10:28 |
dev.cyrusjayson |
``` |
# |
Nov 8th 2019, 10:28 |
slackebot1 |
$validator; } ``` |
# |
Nov 8th 2019, 10:28 |
dev.cyrusjayson |
``` public function validationDefault(Validator $validator) { $validator ->integer('id') ->allowEmptyString('id', null, 'create'); $validator ->scalar('name') ->maxLength('name', 255) ->allowEmptyString('name'); $validator ->scalar('code') ->maxLength('code', 45) ->allowEmptyString('code'); return |
# |
Nov 8th 2019, 10:27 |
challgren |
‘user’ isn’t though |
# |
Nov 8th 2019, 10:27 |
dev.cyrusjayson |
yes ``` protected $_accessible = [ 'user_id' => true, 'name' => true, 'customer_id' => true, 'status_id' => true, 'remarks' => true, 'is_paid' => true, 'date_created' => true, 'customer' => true, 'status' => true, 'suborders' => true ]; ``` |
# |
Nov 8th 2019, 10:27 |
challgren |
is the field accessible? |
# |
Nov 8th 2019, 10:26 |
dev.cyrusjayson |
it just seems cake don’t know user_id added |
# |
Nov 8th 2019, 10:26 |
dev.cyrusjayson |
there is no error though |
# |
Nov 8th 2019, 10:26 |
dev.cyrusjayson |
I cant see it also. and I have association that gives user as null. but the user_id is not also there |
# |
Nov 8th 2019, 10:25 |
challgren |
Check `$entity>errors()` |
# |
Nov 8th 2019, 10:25 |
dev.cyrusjayson |
I added new field name user_id in table [11:14 AM] it is not saving [11:14 AM] even I was passing the data |
# |
Nov 8th 2019, 10:12 |
jotpe |
Hey :wave: |
# |
Nov 8th 2019, 09:31 |
dereuromark |
If they can be null why are they relevant for the query? ;) i think this is a design issue in most cases. |
# |
Nov 8th 2019, 09:25 |
spriz |
I would assume the performance of such query is not great :) :) |