Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if the field is writeable when mapping value to param #735

Merged
merged 5 commits into from
Apr 29, 2024

Conversation

zaniniflz
Copy link
Contributor

Found a small problem when you map the same table field to more than 1 variable, like this:

[MVCTableField('password', [foReadOnly])]
FPassword: string;

[MVCTableField('password', [foWriteOnly])]
FNewPassword: string;

I map the same field password to 2 different variables. The FPassword is read-only and the FNewPassword is write-only.
In this case the TMVCActiveRecord.ExecNonQuery method must discard the read-only mapping, if not the value will be replaced in other loop iteractions.

@danieleteti
Copy link
Owner

Please, check your changes with the updated repo version.

@danieleteti danieleteti self-assigned this Mar 21, 2024
@danieleteti danieleteti added the accepted Issue has been accepted and inserted in a future milestone label Mar 21, 2024
@danieleteti danieleteti added this to the 3.4.2-magnesium milestone Mar 21, 2024
@zaniniflz
Copy link
Contributor Author

@danieleteti
I just pulled changes from your repository to mine. No modifications will be required.

@danieleteti danieleteti merged commit f0bf273 into danieleteti:master Apr 29, 2024
@marcelojaloto
Copy link
Contributor

@danieleteti in the version 3.4.2-magnesium, the enumarator value foWriteOnly is missing. What is happening? What is the new solution?

@danieleteti
Copy link
Owner

danieleteti commented May 21, 2024

Yes, has been removed to improve the whole mechanism.
Look for "FieldOptions" in this article https://www.danieleteti.it/post/delphimvcframework-3-4-2-magnesium/

Also, the activerecord_showcase sample has been updated to show how to use such "FieldOptions".

Here's an extract of the new attributes.

  [MVCTable('customers')]
  TCustomerWithOptions = class(TCustomEntity)
  private
    [MVCTableField('id', [foPrimaryKey, foAutoGenerated])]
    fID: Integer;
    [MVCTableField('code', [foDoNotInsert, foDoNotUpdate])]
    fCode: NullableString;
    [MVCTableField('description', [foDoNotInsert])]
    fCompanyName: string;
    [MVCTableField('city', [foDoNotUpdate])]
    fCity: string;
  public
    property ID: Integer read fID write fID;
    property Code: NullableString read fCode write fCode;
    property CompanyName: string read fCompanyName write fCompanyName;
    property City: string read fCity write fCity;
  end;

@marcelojaloto
Copy link
Contributor

@danieleteti I analyzed the change history of the MVCFramework.ActiveRecord unit and noticed that the foWriteOnly enumerated value was changed to foDoNotSelect. For those who had the problem, search for "foWriteOnly" and don't find anything about it. I suggest you change the post you sent me and the readme to contain this more detailed information.

foWriteOnly = Only allows writing, so it must be accepted in Insert and Update. So it makes sense to be replaced by foDoNotSelect which does not allow reading.

Is it correct?

@danieleteti
Copy link
Owner

danieleteti commented May 21, 2024 via email

@marcelojaloto
Copy link
Contributor

@danieleteti Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Issue has been accepted and inserted in a future milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants