Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8701265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:21:22+00:00 2026-06-13T02:21:22+00:00

In SilverStripe 2.4, I was able to get ID of parent DataObject A in

  • 0

In SilverStripe 2.4, I was able to get ID of parent DataObject “A” in onAfterWrite() method of child dataobject “B” by

$this->AClassID

How to get “A”‘s ID in “B”‘s onAfterWrite() method ?

Note:”A” has many “B”s and “B” has one “A” (one-to-many relationship).

Sample code here for kind consideration:

http://www.sspaste.com/paste/show/507d5222878a7

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:21:24+00:00Added an answer on June 13, 2026 at 2:21 am

    Use if statement to make sure it is not 0 before continuing. like

    if($this->ID){
     //put all your code here
    }
    

    Or

    if($this->RelationName()->ID){
     //put all your code here
    }
    

    The reason is that it is called multiple times and you just need to execute when it is non-zero.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Silverstripe is running on my since a few weeks. Recently, I get an Internal
Using SilverStripe 2.4.7. I've done some searching but I can't seem to be able
I've built an Ecommerce site in Silverstripe and I'm new to this, sorry if
I'm not sure if this is a SilverStripe or a JavaScript issue because I
I am trying to install this theme in SilverStripe: http://www.silverstripe.org/woody-theme/ Here is what I
I'm having trouble with how to do something similar to this http://www.silverstripe.org/archive/show/2431 . Basically
Firstly I'm using version 2.4.7 of SilverStripe. I have a has_one relationship between a
I asked this question on the Silverstripe forum originally. http://www.silverstripe.org/data-model-questions/show/21293 I am trying to
I have used the following query in Silverstripe 2.x projects: $obj = DataObject::get_one('Post', \URLSegment\
In Silverstripe I'm using the method OnBeforeWrite to trigger a function when a page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.