Two tables, with the relationship set up properly in Cakephp:
Property (..., postcode_id,...) and Postcode (id, postcode, latitude, longitude).
A Virtual Field created in Property beforeFind() calculates the distance between a search postcode and the record postcode. Therefore, to get the lat/long, I need to retrieve a record from the Postcode table by the foreign key in the Property record, all within the virtual field declaration.
How can I do this? Multiple SELECTs nested within? Nested find(), which would probably be worse? I thought just using RelatedModel.fieldName would work - it doesn't.
EDIT: Property belongsTo Postcode, Postcode hasMany Property
(Using cakephp v2.4.4)
The Virtual Field in Property beforeFind():
$this->virtualFields['distance'] = 6371 . ' * ACOS(
(SIN(RADIANS(Postcode.latitude)) * ' . $searchPostcode['latitudeSin'] . ') +
(COS(RADIANS(Postcode.latitude)) * ' . $searchPostcode['latitudeCos'] . ') *
COS(RADIANS(Postcode.longitude) - ' . $searchPostcode['longitude'] . ')
)';