Repository navigation
Description
Describe the bug
When generating the detach method for related classes, the id parameter is being converted to all lower case instead of lower camel case. For example, with a reference class called CitizenInt, the detach method is being generated as:
class CitizenIntDetachRowRepository {
const CitizenIntDetachRowRepository._();
/// Detaches the relation between this [CitizenInt] and the [AddressUuid] set in `address`
/// by setting the [CitizenInt]'s foreign key `id` to `null`.
///
/// This removes the association between the two models without deleting
/// the related record.
Future<void> address(
_i1.Session session,
CitizenInt citizenint, { // <-- Should be `citizenInt`, with capital "I" for the second word.
_i1.Transaction? transaction,
}) async {To reproduce
Create two models with more than one word in the name (i.e.: AddressUuid and CitizenInt) and with object relations to each other:
class: AddressUuid
table: address_uuid
fields:
street: String
inhabitantId: int?
inhabitant: CitizenInt?, relation(name=citizen_address, field=inhabitantId)
indexes:
inhabitant_uuid_index_idx:
fields: inhabitantId
unique: trueclass: CitizenInt
table: citizen_int
fields:
name: String
address: AddressUuid?, relation(name=citizen_address)Now check the generated CitizenIntRepository to see that the address method of the CitizenIntDetachRowRepository has the parameter citizenint (all lower case), while the address method of the CitizenIntAttachRowRepository has the parameter correctly generated as citizenInt.
class CitizenIntAttachRowRepository {
const CitizenIntAttachRowRepository._();
/// Creates a relation between the given [CitizenInt] and [AddressUuid]
/// by setting the [CitizenInt]'s foreign key `id` to refer to the [AddressUuid].
Future<void> address(
_i1.Session session,
CitizenInt citizenInt, // Correct
_i2.AddressUuid address, {
_i1.Transaction? transaction,
}) async {class CitizenIntDetachRowRepository {
const CitizenIntDetachRowRepository._();
/// Detaches the relation between this [CitizenInt] and the [AddressUuid] set in `address`
/// by setting the [CitizenInt]'s foreign key `id` to `null`.
///
/// This removes the association between the two models without deleting
/// the related record.
Future<void> address(
_i1.Session session,
CitizenInt citizenint, { // Incorrect
_i1.Transaction? transaction,
}) async {Expected behavior
The CitizenInt parameter should preserve the case of the class name, with only the first letter as lower case - such as already happens for the attach repository.
Library version
2.4.0
Platform information
Windows
Additional context
The issue is probably caused by the conversion to lower camel case in the _buildDetachRowFromObjectRelationField method of the repository_classes.dart file:
Method _buildDetachRowFromObjectRelationField(String className,
SerializableModelFieldDefinition field, ClassDefinition classDefinition) {
return Method((methodBuilder) {
var classFieldName = className.toCamelCase(isLowerCamelCase: true); // this should be `.camelCase`
var fieldName = field.name;
var relation = field.relation as ObjectRelationDefinition;
var idTypeReference = relation.parentTableIdType.reference(
serverCode,
nullable: false,
subDirParts: classDefinition.subDirParts,
config: config,
) as TypeReference;The toCamelCase function is prepared to convert from words separated by spaces or underscores, but not terms that are already as some camel case form. All other parts of the repository_classes.dart use the .camelCase method of the recase package.
How experienced are you with this library?
Expert - Experienced and comfortable with using this library in complex projects
Are you interested in working on a PR for this?
- I want to work on this
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone 🚀
Activity
SandPod commentedon Apr 7, 2025
Thanks for reporting this! 👍
Since this will change the generated interface we will need to fix this in the next major version.
SandPod commentedon Oct 24, 2025
This is actually not a breaking change since it modified a positional parameter.