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

Awards for the best Joomla app. This product is gonna win an award for this amazing job. Cook Self Service is the the best application from all over the Joomla universe ! It brings Joomla to a professional level really advanced for developers. It is a real fun to develop with it. The ACL part and security checks implementation are just... so much hours saved. I can now concentrate myself more on the design part and the creative works. Thank you so much. Guys I offer you all my congratulation ! Keep up the works because Joomla is needing it to increase the quality of extensions availables on the JED. I also learned a lot because I can see how to code at the proper place and I found all my answers reading the forum.
lack_hanson (JED)
          

Get Started