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.074 seconds

Amazing Tool !
And only tool I know that allows complete Scaffolding in terms of component creation. It really saves loads of time (actually much more than that). Simple architecture enables quick and painless changes at any time. Code is clean and consintent. It's just... what's the word... neat! :) Great work! You should definetely try this one!

pi_wo (JED)
         

Get Started