Add parent_prefix_id field to Prefix object / API #9857

Closed
opened 2025-12-29 21:23:37 +01:00 by adam · 3 comments
Owner

Originally created by @tgoodsell-tempus on GitHub (Jun 17, 2024).

NetBox version

v4.0.3

Feature type

Data model extension

Proposed functionality

Add a parent_prefix_id field to the Prefix API object which is populated with the ID value of the Parent Prefix object if it exists. This means the value would only be populated if this is a child of an actual created Prefix within the same VRF. Value would only be the direct parent (depth - 1 in the tree) value.

Use case

Currently, when you do a GET on a Prefix, you'll receive the children and _depth fields which help indicate where the Prefix is amongst a tier of next prefixes. However, you still must leverage a separate search function to find the particular parent prefix, when doing the API ops.

Adding this field would allow us to avoid needing to implement that search logic, which would be important for API clients performing Prefix management leveraging the hierarchical functions and the available prefix API.

Database changes

TBD: My first thought would be to add this onto the mechanism which populates _depth itself, just taking the ID of the _depth - 1 Prefix and adding that to the model via populating the new field. Otherwise we can leave the field as null.

External dependencies

No response

Originally created by @tgoodsell-tempus on GitHub (Jun 17, 2024). ### NetBox version v4.0.3 ### Feature type Data model extension ### Proposed functionality Add a `parent_prefix_id` field to the Prefix API object which is populated with the ID value of the Parent Prefix object if it exists. This means the value would only be populated if this is a child of an actual created Prefix within the same VRF. Value would only be the direct parent (depth - 1 in the tree) value. ### Use case Currently, when you do a `GET` on a Prefix, you'll receive the `children` and `_depth` fields which help indicate where the Prefix is amongst a tier of next prefixes. However, you still must leverage a separate search function to find the particular parent prefix, when doing the API ops. Adding this field would allow us to avoid needing to implement that search logic, which would be important for API clients performing Prefix management leveraging the hierarchical functions and the available prefix API. ### Database changes TBD: My first thought would be to add this onto the mechanism which populates `_depth` itself, just taking the ID of the `_depth - 1` Prefix and adding that to the model via populating the new field. Otherwise we can leave the field as `null`. ### External dependencies _No response_
adam added the type: featurestatus: duplicatenetbox labels 2025-12-29 21:23:37 +01:00
adam closed this issue 2025-12-29 21:23:37 +01:00
Author
Owner

@tgoodsell-tempus commented on GitHub (Jun 17, 2024):

Depending on if this idea is accepted, I would be willing to volunteer for implementation work.

@tgoodsell-tempus commented on GitHub (Jun 17, 2024): Depending on if this idea is accepted, I would be willing to volunteer for implementation work.
Author
Owner

@arthanson commented on GitHub (Jun 18, 2024):

@tgoodsell-tempus good suggestion, there are some technical challenges behind it as it would be semi-blocked by #7845 would probably be done as part of that feature work.

@arthanson commented on GitHub (Jun 18, 2024): @tgoodsell-tempus good suggestion, there are some technical challenges behind it as it would be semi-blocked by #7845 would probably be done as part of that feature work.
Author
Owner

@jeremystretch commented on GitHub (Mar 14, 2025):

We can fold this into #7845, because it's reasonable to expect that we would expose the proposed foreign key relationship directly within the REST API.

@jeremystretch commented on GitHub (Mar 14, 2025): We can fold this into #7845, because it's reasonable to expect that we would expose the proposed foreign key relationship directly within the REST API.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9857