Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

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

  • dyvel
  • dyvel's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 200
  • Thank you received: 11
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

Please Log in or Create an account to join the conversation.

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

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

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.113 seconds

The j-cook project is one of the best of its kind and it is nice that we all try to contribute in little ways to make life easy for each other.

vlemos (Forum)  

Get Started