# How to made the domain based on another table?

**URL:** <https://discuss.tryton.org/t/how-to-made-the-domain-based-on-another-table/2809>\
**Category:** Developer\
**Created:** [June 1, 2020, 8:47am UTC](https://discuss.tryton.org/t/how-to-made-the-domain-based-on-another-table/2809 "2020-06-01T08:47:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bala4901](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/fbc32d/32.png) [@bala4901](https://discuss.tryton.org/u/bala4901)\
**Post date:** [June 1, 2020, 8:47am UTC](https://discuss.tryton.org/t/how-to-made-the-domain-based-on-another-table/2809/1 "2020-06-01T08:47:44Z")

</div>

Hi

I would like to domain records from another table, is it possible?

Example:

```
def ModelA:
	__name__ = 'test.modela'
	
	name = fields.Char('Name')
	lines = fields.One2Many('test.modela.line', 'modela', 'Model A')
	
def ModelALine:
	__name__ = 'test.modela.line'
	
	modela = fields.Many2One('test.modela', 'Model A')
	employee = fields.Many2One('company.employee', 'Approver')
	
def ModelC:
	__name__ = 'test.modelc'
	
	name = fields.Char('Name')
	modela = fields.Many2One('test.modela')
	employee = fields.Many2One('company.employee', 'Approver', domain=[])

```

For this kind of Model Setup, For “Model C”, I would like domain/filter the emloyees which only exist on model “ModelALine”, after user select fields of “modela”?

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [June 1, 2020, 9:09am UTC](https://discuss.tryton.org/t/how-to-made-the-domain-based-on-another-table/2809/2 "2020-06-01T09:09:22Z")

</div>

domain can only have one field (as operand) per clause.  
You must create a function field that exposes the available employees on the `ModelC` so it can be evaluated as value of the domain clause.

---

<div class="post-metadata">

**Author:** ![bala4901](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/fbc32d/32.png) [@bala4901](https://discuss.tryton.org/u/bala4901)\
**Post date:** [June 1, 2020, 9:32am UTC](https://discuss.tryton.org/t/how-to-made-the-domain-based-on-another-table/2809/3 "2020-06-01T09:32:47Z")

</div>

```
def ModelC:
    "Model C Line"
	__name__ = 'test.modelc'
	
	name = fields.Char('Name')
	modela = fields.Many2One('test.modela', 'Model A')
	employee_ids = fields.Function(fields.Char('Employee Ids', depends=['modela']), 'get_employee_ids')
	employee = fields.Many2One('company.employee', 'Approver', domain=[('id', 'in', [Eval('employee_ids')])], depends=['employee_ids'])
	
	
	def get_employee_ids(self, name=None):
		_ids = []
		if self.modela:
		    for m in self.modela:
               _ids.append(m.employee.id)
        if _ids:
		    return ','.join(_ids)
		return "-1"

```

I try to sub another fields for getting the Ids, however, it do not return any value during creating a new record.

Am I doing a wrong way?

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [June 1, 2020, 9:34am UTC](https://discuss.tryton.org/t/how-to-made-the-domain-based-on-another-table/2809/4 "2020-06-01T09:34:32Z")

</div>

You can not use Char as value for a domain against a Many2One. It must be a list of ids so a Many2Many.
