Websites v4 docs v5.2.4
    Preparing search index...

    Module API Reference/Models

    Models are used to interact with APIs and represent data.

    Each Model represents a resource, such as a Property, Branch or Article.

    Most models share these async static methods:

    • findById()
    • findOne()
    • findAll()

    These methods will return a Promise which resolves to return an object containing either result: an instance of the class (in the case of findOne and findById), or results: an array of instances (in the case of findAll). For example:

    // `result` will be an instance of the Property model
    const { result: property } = await Property.findById(12345);

    // articles will be an array of instances of the Article model
    const { results: articles } = await Article.findAll({ topic: 'news' });

    Each model has various instance getters (accessors) to interact with the model instance. Typically these render data, e.g.

    // renders the property ID: 12345
    property.id

    Although getters run like normal methods they do not need to be invoked using ().

    In case you need to access any data which does not have a getter, you can access the data directly using the get() instance method available on every model:

    property.get('display_address');
    

    When fetching multiple resources, it’s often beneficial for performance to resolve the promises concurrently using Promise.all():

    // omitting 'await' here so the promise is returned
    const heroChunkPromise = ContentChunk.find({ name: 'home_hero' });
    const sidebarChunkPromise = ContentChunk.find({ name: 'home_sidebar' });

    const [heroChunk, sidebarChunk] = await Promise.all([heroChunkPromise, sidebarChunkPromise]);

    You can also limit the fields that are returned - this can significantly reduce response times and therefore improve performance:

    Note that the string values in the fields array should correspond to the Hestia data keys.

    const {
    results: branches,
    errors,
    pagination,
    } = await Branch.findAll({
    pageSize: 12,
    page: 1,
    // if we only need the ID and name of each branch, specify that here
    fields: ['branch_id', 'branch_name'],
    });

    There is a directory serializers/ (see Serializers) containing functions to specify the way models should be serialized to JSON. Because models are complex objects they cannot be passed to client-side code in the same form as they exist on the server, so they must be converted to serializable versions of those objects. The simplest way to do this is to combine JSON.parse() and JSON.stringify().

    // in async server component
    const { result: property } = await Property.findById(1234);

    const serializableProperty = JSON.parse(JSON.stringify(property));

    return (
    // 'property' inside the client component will be the object returned by the property serializer
    <MyClientComponent property={serializableProperty} />
    )

    Consider performance when adding new values to a serializer as each method or accessor will be called when constructing the JSON.

    Enumerations

    LeadType
    WebsiteSalesStatusOption

    Classes

    AdminUser
    Agency
    AgencyEmployee
    Article
    Branch
    CalendarEvent
    Connection
    ContentChunk
    County
    HometrackPropertyMarketStatistic
    Image
    InstantValuation
    Lead
    Location
    Page
    Place
    Postcode
    Property
    StampDutyRate
    Testimonial
    User

    Interfaces

    AgencyEmployeeEnquiryParams
    AgencyRegistrationLeadParams
    AuthResponse
    BaseLead
    BookViewingLeadParams
    BranchEnquiryParams
    EmailPortalLeadParams
    FormattedStatistic
    HestiaBasePlace
    HestiaBranchesResult
    HestiaCountyData
    HestiaLocationData
    HestiaPostcodeData
    HestiaPropertiesResult
    InstantValuationLeadParams
    MarketingPreferences
    ModelError
    ModelStatic
    MortgageEnquiryLeadParams
    PropertyCardProps
    PropertyHestiaSearchParams
    PropertyListSearchParams
    PropertyResultsProps
    PropertySearchParams
    RegisterResponse
    RequestDetailsLeadParams
    SessionCookie
    SessionsResponse
    SimilarPropertiesSearchParams
    UserCreateParams
    UserData
    UserUpdateParams
    UserUpdateResponse
    ValuationRequestLeadParams

    Type Aliases

    AgencyContentItem
    AgencyMenu
    AgencyPreferences
    AgencyPreferencesCamel
    ArticleAuthor
    ArticleModelSearchParams
    Attachment
    BranchDepartment
    BranchFeaturedProperty
    BranchHestiaFields
    BranchHestiaSearchParams
    BranchOpeningHours
    BranchSearchParams
    CalendarEventsSearchParams
    CarouselItem
    CountriesWithRatesByTaxTypes
    Country
    CreateImage
    CSPHeaders
    CustomForm
    CustomFormParams
    CustomLeadsApiResponse
    DBAPIAgency
    DbapiArticleAssetElement
    DbapiArticleAssociation
    DbapiArticleAuthorElement
    DbapiArticleBranchElement
    DbapiArticleTopicElement
    DBAPIBaseAssociation
    DBAPIBaseElement
    DBAPIBookViewingLeadsData
    DBAPIBranchData
    DBAPIBranchForeignKeysData
    DBAPIBranchMetadata
    DBAPIBranchResult
    DBAPICalendarEvent
    DBAPICalendarEventByIdResult
    DBAPICalendarEventsResult
    DBAPIEmailPortalData
    DBAPIFee
    DBAPIHometrackPropertyMarketStatistic
    DBAPIHometrackPropertyMarketStatisticsResult
    DBAPIMedia
    DBAPIPropertyData
    DBAPIRequestDetailsLeadsData
    DBAPISharingPermission
    DBAPISiteData
    DBAPISiteElement
    DBAPIStampDutyRateData
    DBAPITestimonialData
    DBAPIValuationRequestData
    FormElement
    HestiaAgencyData
    HestiaBranchData
    HestiaBranchResponse
    HestiaContentChunkData
    HestiaContentChunksResult
    HestiaCountyResult
    HestiaDepartment
    HestiaFeatureProperty
    HestiaLocationResult
    HestiaNews
    HestiaOpeningTime
    HestiaOpeningTimeJoined
    HestiaPageData
    HestiaPageResult
    HestiaPhoto
    HestiaPlaceData
    HestiaPlaceResult
    HestiaPlacesResult
    HestiaPostcodeResult
    HestiaPropertyData
    HestiaPropertyId
    HestiaPropertyMetadata
    HestiaService
    HestiaTestimonialData
    HestiaTestimonialsResult
    HestiaUSP
    HFAEUpdateData
    HometrackPropertyMarketStatisticsSearchParams
    ILead
    ImagesAPICreateResponse
    ImagesAPIMedia
    InstantValuationApiResponse
    InstantValuationErrorType
    InstantValuationParams
    InstantValuationResult
    LeadParams
    LeadsApiResponse
    MarketingPreferencesResponse
    PasswordResetCreateResponse
    PasswordResetUpdateParams
    PasswordResetUpdateResponse
    PropertyTypeStatistics
    RoomDetail
    SalesPipelineElement
    SelectableCountries
    StampDutyRatesByTaxType
    Statistics
    TaxTypes
    UserUpdateSnakeParams
    USP
    WantedAd

    Variables

    DEFAULT_MARKETING_STATEMENT_TEXT
    DEFAULT_TERMS_STATEMENT_TEXT
    WEBSITE_SALES_STATUS_BY_IDENTIFIER_AND_TEXT