How it works...

Related fields are just like regular fields, but they have an additional attribute, related, with a string for the separated chain of fields to traverse.

In our case, we access the publisher related record through publisher_id, and then read its city field. We can also have longer chains, such as publisher_id.country_id.country_code.

Note that in this recipe, we set the related field as readonly. If we don't do that, the field will be writable, and the user may change its value. This will have the effect of changing the value of the city field of the related publisher. While this can be a useful side effect, caution needs to be exercised; all the books that are published by the same publisher will have their publisher_city field updated, which may not be what the user expects.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset