How to create relationships on non id fields is not clear
See original GitHub issueSince Watermelon auto assigns the id field, I’m trying create a relationship between two models on non ‘id’ fields as per their relationship on the remote resource. the example would be:
class Pledge extends Model {
static table = 'pledges'
static associations = {
profiles: { type: 'belongs_to', key: 'id_profile' },
}
@field('pledge_id') pledgeId
@field('owner') owner
@field('amount') amount
@relation('profiles', 'id_profile') profile
}
class Profile extends Model {
static table = 'profiles'
static associations = {
pledges: { type: 'has_many', foreignKey: 'id_profile' }
}
@field('addr') addr
@field('type') type
@field('name') name
@field('id_profile') idProfile
@children('pledges') pledges
When I try to create the Pledge
on pledge.profile.set(profile.id)
the profile is not set and id_profile
is “0” when it should have a value.
So this is two questions.
- Would this be the ideal way to model this relationship in Watermelon?
- Is this the correct way to create the Pledge record?
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Create, edit or delete a relationship - Microsoft Support
The Edit Relationships dialog box appears. Select the Enforce Referential Integrity check box. Select either the Cascade Update Related Fields or the Cascade...
Read more >Enforcing Referential Integrity on Table Relationships - YouTube
... relationships between two tables in Microsoft Access using t... ... the Cascade Update Related Fields and Cascade Delete Related Records ...
Read more >Object Relationships Overview - Salesforce Help
Clearing the field is a good choice when the field doesn't have to contain a value from the associated lookup record.
Read more >Single-criteria relationships - FileMaker Pro
In the Contacts table, the Customer ID is a simple number field, so do not set any auto-entry options, but set the field...
Read more >The 6 Types of Relationships in Salesforce
Lookup fields are not required on the page layout of the detail record but if you make them a required field, it is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For now I resorted to creating these relationships on the
id
fields during the data import and keeping their remote id’s on{model}Id
field. I will see if this degrades into something problematic for me.@radex Is it still not possible to create a relation on non
_id
fields?