Welcome, Guest
Username: Password: Remember me

TOPIC: How to filter based on a relation in ORM

How to filter based on a relation in ORM 23 Apr 2019 12:14 #15724

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
Hi

in my prepareQuery in my model I have this
$this->orm->select(array(
	'end_date',
	'ordering',
	'start_date',
	'teamnumber',
	'title',
	'venue',
	'venue.title',
));

// LOAD Indstructors (N:m relation)
$this->orm->relation('indstructors', array(
	'select' => 'first_name'
));

$this->orm->filter('indstructors.user_id', array(
    'value' => $userid,
));

Problem is, my filter is not working. Im getting this error: 0 Unknown column '_indstructors_.user_id' in 'where clause'

How can I create a filter, based on a value from a relation table?

Thanks
The administrator has disabled public write access.

How to filter based on a relation in ORM 23 Apr 2019 21:53 #15726

  • Nicolas
  • Nicolas's Avatar
  • Offline
  • Senior Member
  • Posts: 72
  • Thank you received: 11
  • Karma: 5
Hi Dyvel
Sorry for my answer time, on my phone it's more complicated to answer with a code

You are in the model, so the ORM system is simpler.
link to docs : ORM Système → Relations→ Nested queries

I don't know your tables, but you can do something like this:
$this->orm(array(
	'select' => array(
		'end_date',
		'ordering',
		'start_date',
		'teamnumber',
		'title',
		'venue',
		'venue.title',
		//add the FK spaceName for instructors
		'instructors.user_id',
		'instructors.first_name
	),
	'relation' => array(
		//'relationModel' => selectArray
		'indstructors' => array(
			'select' => 'first_namename'
		)
	),
	'filter' => array(
		// Filter by FK
		'instructors.user_id' => array(
			'type' => 'fk'
		),
	)
));

think about changing nameSpace or relation name. I don't know your tables
It should work.

Nicolas
The administrator has disabled public write access.
Time to create page: 0.073 seconds

Get Started