A reference points at its own dataset
A [Reference] points back at the dataset the item lives in. Bevel cannot resolve that.
What it means
References link items in one dataset to items in another. An item cannot point at items in its own dataset, because those items do not exist yet when it is built.
Example message
Data/Posts/BlogPost.cs(6,15): error BEVEL094: Dataset 'Posts': [Reference("Posts")] on 'BlogPost.Related' points at its own dataset. Bevel does not resolve references within one dataset, because items would have to exist before they are built. Store the keys instead (for example 'string[] RelatedSlugs') and look the items up when the page renders, for example: Data.Posts.Where(p => blogPost.RelatedSlugs.Contains(p.Slug)). Mark the key with [Unique] so each lookup finds one item. Help: https://khalidabuhakmeh.github.io/bevel/reference/diagnostics/bevel094/
How to fix
Store the keys, then look the items up in your Razor component.
public sealed record BlogPost(string Title)
{
[Reference("Posts")]
public List<BlogPost> Related { get; init; }
public string[] RelatedSlugs { get; init; } = [];
[Unique]
public string Slug { get; init; } = "";
}
@foreach (var post in Data.Posts.Where(p => Post.RelatedSlugs.Contains(p.Slug)))
{
<a href="@(Links.To<PostPage>(post))">@post.Title</a>
}
See References for how references between two datasets work.