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

Add autofetching for useful pks #36

Closed
patricklatimer opened this issue Sep 24, 2024 · 2 comments
Closed

Add autofetching for useful pks #36

patricklatimer opened this issue Sep 24, 2024 · 2 comments

Comments

@patricklatimer
Copy link
Collaborator

New records being added often have foreign keys they need to provide, such as test_pk in the following example:

class SlimsWaterlogResult(SlimsBaseModel):
    """Model for a SLIMS Waterlog Result, the daily water/weight records

    Examples
    --------
    >>> from aind_slims_api.core import SlimsClient
    >>> from aind_slims_api import models
    >>> client = SlimsClient()
    >>> mouse = client.fetch_model(models.SlimsMouseContent, barcode="00000000")
    >>> test_pk = client.fetch_pk("Test", test_name="test_waterlog")

    Write waterlog result.
    >>> waterlog_result = client.add_model(
    ...  models.SlimsWaterlogResult(
    ...   mouse_pk=mouse.pk,
    ...   date=datetime(2021,1,1),
    ...   weight_g=20.0,
    ...   water_earned_ml=5.0,
    ...   water_supplement_delivered_ml=5.0,
    ...   water_supplement_recommended_ml=5.0,
    ...   total_water_ml=10.0,
    ...   comments="comments",
    ...   workstation="aibs-computer-id",
    ...   test_pk=test_pk,
    ...  )
    ... )
"""

It shouldn't be on the user to fetch those, we should add some way that the client lazily fetches those kinds of pks when it needs them, or populates the cache based on already-fetched models of that same type.

@mochic
Copy link
Collaborator

mochic commented Sep 25, 2024

I think that the Mouse interface in #33 is a really convenient way to interact with the data. Maybe this autofetching can go there. I believe automatic behavior at the top level is easiest (easier to toggle off too). A custom type for fetching pks could also just be added to models too if you think automatic fetching on the model level is still valuable. In my mind it would be a serialization of the args fed into fetch_pks.

@patricklatimer
Copy link
Collaborator Author

I think you're right that this belongs in the Operations code, I'll close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants