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.106 seconds
  I still don't believe he can really be human to do all this ! From all of the forums that I've ever participated in this is certainly the one that most encapsulates the feeling of being truly open source where everyone's opinions and contributions can and will shape the development of the service! It's truly awesome! Hope you enjoy cooking and look forward to reading and contributing to any of the editorial work that you proposed too!! Thanks
Gez (audibleid - JED)

Get Started