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

Allow Custom Attribute Name for created_at #871

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mmaa
Copy link

@mmaa mmaa commented Jan 5, 2025

By default, Phoenix uses inserted_at for the column name in timestamps(). This allows the customization of the created_at attribute name to align with Phoenix defaults.

@mmaa mmaa marked this pull request as draft January 5, 2025 22:51
Copy link
Collaborator

@zachdaniel zachdaniel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to define a test for this purpose. use the token extension in a resource inside that test. Then you can assert on which attributes it has using Ash.Resource.Info.attributes(TokenResource).

test "uses created_at" do
  defmodule Token do
    use Ash.Resource, extensions: [....]
  end

  assert Ash.Resource.Info.attribute(Token, :inserted_at)
end

@mmaa mmaa force-pushed the mmaa/token_created_at_attribute_name branch 2 times, most recently from e3a5261 to 733991f Compare January 22, 2025 15:44
@mmaa
Copy link
Author

mmaa commented Jan 22, 2025

Thanks, @zachdaniel. I've added a test which confirms that this change is actually not working as expected. Looks like I'm still missing something.

Using create_timestamp :inserted_at does give me the attribute :inserted_at, but I still end up with a :created_at:

> Ash.Resource.Info.attribute_names(Example.TokenWithCustomCreateTimestamp)
MapSet.new([:inserted_at, :extra_data, :purpose, :created_at, :jti, :expires_at, :subject, :updated_at])

@zachdaniel
Copy link
Collaborator

Hm...that's pretty strange. Is the timestamps() constructor being used somewhere?

@mmaa
Copy link
Author

mmaa commented Jan 22, 2025

The only references to timestamps are in the install task and test.

@zachdaniel
Copy link
Collaborator

Interesting. I'd have to investigate further but the only other place it could be coming from is the token extensions transformer. Could thing else be adding that created at?

@mmaa mmaa force-pushed the mmaa/token_created_at_attribute_name branch from 733991f to aada235 Compare January 22, 2025 23:34
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

Successfully merging this pull request may close these issues.

2 participants