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 morphs helper to blueprint #228

Merged
merged 2 commits into from
Oct 29, 2020

Conversation

girardinsamuel
Copy link
Contributor

Added morphs to ease polymorphism relationships creation.
Still following Like,Article,Comment example we can now do:

# likes migration
table.morphs("record")
  • I did not setup an index automatically (between record_type and record_id) as done in Orator, should we do that ?
  • I just created a test for proof, but what's the policy for testing "blueprints columns", they seems not tests except few, should I remove the test ? And should we do it for each connection ?

@girardinsamuel
Copy link
Contributor Author

@josephmancuso ready for review with some questions

Copy link
Member

@josephmancuso josephmancuso left a comment

Choose a reason for hiding this comment

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

Looks great.

"""
self._last_column = self.table.add_column(
"{}_id".format(column), "unsigned_integer", nullable=nullable
)
Copy link
Member

Choose a reason for hiding this comment

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

hmm. What about in the case someone does:

table.morphs('record').nullable()

? We might have to add self._last_column as a list or tuple and then nullable will act on all the elements in the list? Same actually goes for table.timestamps() too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not thought about that, I'll look into it

@girardinsamuel
Copy link
Contributor Author

@josephmancuso and what about this part :

I did not setup an index automatically (between record_type and record_id) as done in Orator, should we do that ?

@josephmancuso
Copy link
Member

I did not setup an index automatically (between record_type and record_id) as done in Orator, should we do that ?

I don't see why not. Maybe have that as a parameter. morphs(indexes=True). have it default to true


Returns:
self
"""
self._last_column.nullable()
_columns = []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@josephmancuso Here I deal with multiple columns locally in nullable() method but we could also have done it globally in the Blueprint class by always using self._last_column as a list.
Don't know what's best

@josephmancuso josephmancuso merged commit 959d126 into MasoniteFramework:0.7 Oct 29, 2020
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.

None yet

2 participants