What is the best design for this use case regarding bidirectional relationship?

For this question let’s consider a system in which the users can match with each other (let’s say for simplicity exactly like the dating apps).

User1 matches User2 (and the other way around) only in one of the following cases 1. they both like each other 2. one of them special likes the other one and the other one just likes 3. both of them special like each other

The match will be stored in a SQL database, and when the users log in the app they need to fetch their matches, also the information if they were special liked, or special liked, or both.

The design question here is regarding the match entity storage and concept, whether it should be considered as two entities or one.

The first approach is as follows:

create table matches (     id                     char(36)                            not null,     first_user_id          int unsigned                        not null,     second_user_id         int unsigned                        not null,     first_user_superliked  tinyint(1)                          not null,     second_user_superliked tinyint(1)                          not null,     created_at             timestamp default CURRENT_TIMESTAMP not null     PRIMARY KEY (id) ) 

The id will be an unique uuid, so one match will have only this one entity for both users. The fetch query will have to query both first_user_id and second_user_id fields. Example, user with id 4 logs in and need to see his matches, query will be like:

SELECT * FROM matches WHERE first_user_id = 4 OR second_user_id = 4 

The second approach requires two rows for one match, each obviously will have different ids. The structure:

create table matches (     id                     char(36)                            not null,     user_id                int unsigned                        not null,     matchee_id             int unsigned                        not null,     did_superlike          tinyint(1)                          not null,     was_superliked         tinyint(1)                          not null,     created_at             timestamp default CURRENT_TIMESTAMP not null     PRIMARY KEY (id) ) 

With this approach if we want to get the matches of user with id 4, we have to query only based on the field user_id If someone unmatches the other user, we have to delete both rows (or disable via some flag)

As software engineers, what do you think is the best approach for this scenarios ?

I provided a match example, but my question is in general for bidirectional relationships of this type as I see them quite often and would like other opinions in order to improve myself

What is the best design for this use case regarding bidirectional relationship?

For this question let’s consider a system in which the users can match with each other (let’s say for simplicity exactly like the dating apps).

User1 matches User2 (and the other way around) only in one of the following cases 1. they both like each other 2. one of them special likes the other one and the other one just likes 3. both of them special like each other

The match will be stored in a SQL database, and when the users log in the app they need to fetch their matches, also the information if they were special liked, or special liked, or both.

The design question here is regarding the match entity storage and concept, whether it should be considered as two entities or one.

The first approach is as follows:

create table matches (     id                     char(36)                            not null,     first_user_id          int unsigned                        not null,     second_user_id         int unsigned                        not null,     first_user_superliked  tinyint(1)                          not null,     second_user_superliked tinyint(1)                          not null,     created_at             timestamp default CURRENT_TIMESTAMP not null     PRIMARY KEY (id) ) 

The id will be an unique uuid, so one match will have only this one entity for both users. The fetch query will have to query both first_user_id and second_user_id fields. Example, user with id 4 logs in and need to see his matches, query will be like:

SELECT * FROM matches WHERE first_user_id = 4 OR second_user_id = 4 

The second approach requires two rows for one match, each obviously will have different ids. The structure:

create table matches (     id                     char(36)                            not null,     user_id                int unsigned                        not null,     matchee_id             int unsigned                        not null,     did_superlike          tinyint(1)                          not null,     was_superliked         tinyint(1)                          not null,     created_at             timestamp default CURRENT_TIMESTAMP not null     PRIMARY KEY (id) ) 

With this approach if we want to get the matches of user with id 4, we have to query only based on the field user_id If someone unmatches the other user, we have to delete both rows (or disable via some flag)

As software engineers, what do you think is the best approach for this scenarios ?

I provided a match example, but my question is in general for bidirectional relationships of this type as I see them quite often and would like other opinions in order to improve myself

Ruby on Rails newbie question, regarding general design for models/controlers for feedback app/ my thinking

I am working on a little project which essentially allows me as the administrator to upload new products to the app (each product would be a video explaining product) which would have its own specific questionaire (specific to product), and as admin input which users are allowed to see this product and answer the product specific questionaire (send to specific email addresses, each product has different questions and different number of Qs). Users who were selected for a product would receive a link to their email and come to the site and answer the questionaire for the product. Once the user fills out questionaire and submits they will not be able to see the product again.

So I am just thinking about the general design for this app. Keep in mind I do not have a ton of experience so maybe my thinking is not the best. Here is what I had in mind.

Models: Product (description, video (through active storage), completed_users(list of users who have completed and can currently can not see product)),:has Questionaire? :has Users (list of users who still have access to product for review)

Users (demographic info, name, finishedReview(list of products already veiws by user)) :has Product? (the products they still haven’t review, which would be deleted after review?)

Questionaire belongs to Product (do I need a questionaire specific model? Or just keep each products questions in an array in Product? (each would be different length))

Also I am trying to think specifically how to implement each product having a different questionnaire with different lengths and questions. I guess I am confused sometimes when to create a model and when to just keep it in one model as an attribute. Is the model made in this situation if it will be used by multiple other models?

Thanks for any help on my thoughts for this, love to hear some feedback!

How do I adjudicate the logic modality of certain death regarding the Fast Friends spell?

When I cast the Fast Friends spell could I assign the afflicted target to a task that leads to a die roll that has a chance of 98% from death by falling damage without the spell ending immediately?

If the activity would result in certain death for the creature, the spell ends.

Does the task have to necessarily lead to death for the spell ending condition to take place?

How do I adjudicate death probabilities for the purpose of the duration of the Fast Friends spell?

Seeking Advice Regarding Google’s Reconsideration Request

Hi Folks! One of our clients is facing Manual Actions by Google so we had to file a reconsideration request. Apparently, a large number of links were placed on Chinese, Russian websites, most of them spam, possibly by their competitors. We pulled out the links data from Ahrefs, GSC, CognitiveSEO, Majestic & a few other places. We went one by one across each link, scanning them and trying to determine if it was a spam link or artificial link. Then we pulled out contact information (from…

Seeking Advice Regarding Google's Reconsideration Request

An alternative for State pattern, regarding object immutability [on hold]

In his blog post, “Design Patterns and Anti-Patterns, Love and Hate”, Yegor256 excludes State pattern from good patterns and says:

Although it’s not implied, I feel that in most cases the use of this pattern results in mutability, a code characteristic that I’m generally against.

But he doesn’t provide any further explanation.

I wonder whether there’s an alternative for state pattern not relying on mutable objects? Can mutability in the case of State pattern bring so much problem that makes using this pattern more burden than not using it at all?

* Comments are closed in the original post, otherwise I would’ve asked the question there.

Can someone help clear up some confusion regarding the proof of Mordell-Weil Theorem?

I’m reading the proof(s) of Mordell-Weil theorem using various texts. This post is to make sure what I’m reading and understanding is correct..

Rational points on Elliptic Curves by Silverman Tate gives a proof of Mordell ‘s theorem when elliptic curves are over rationals, $ \mathbb{Q}$ and have at least one rational $ 2$ -torsion point.

Then I noticed that Lawrence Washington’s book on Elliptic curves also discuss this result this, first when all roots of cubic $ f(x)$ are in $ \mathbb{Q}$ and then just one of them is in $ \mathbb{Q}$ . And the same goes for Cassels’ and Knapp’s book as well.

Then Lawrence Washington gives a remark that same can be said (i.e., Mordell-Weil holds) when we consider elliptic curves ($ y^2 = f(x)$ ) over any number field $ K$ and $ f(x)$ has all roots in $ K$ as we can prove Weak Mordell Weil in this case with some modification of the usual $ \mathbb{Q}$ argument. But then it says nothing about the case when we just assume that $ f(x)$ has at least one zero in $ K$ .

Now my questions,

(1) I’m assuming that we can give a proof of Mordell-Weil when elliptic curves are over K and $ f(x)$ has (just) at least one point in $ K$ . And I think Silverman Tate’s proof in case of $ \mathbb{Q}$ can be generalized, mainly Weak Mordell-Weil’s (Lemma $ 3.4$ in the book)

(2) What happens when elliptic curves ($ y^2=f(x)) E(\mathbb{Q})$ and $ E(K)$ have no $ 2$ -torsion point or $ f(x)$ has no root in $ \mathbb{Q}$ (respectively $ K$ ) ? Is it the situation that is discussed in the J.S.Milne’s Elliptic Curves book or J. Silverman’s The Arithmetic of Elliptic Curves?

I would appreciate if someone could help answer some or all of the questions above or maybe just refer to an appropriate source to find these proofs/ discussions.

Thank you!

python returns error regarding attributes when using stripped_strings while parsing a html content. This html content is added to the class

python returns error regarding attributes when using stripped_strings while parsing a html content. This html content is added to the class. Here is the code snippet, the data that needs to be extracted is part of a list.

import requests         from bs4 import BeautifulSoup          class RESTApp:             url = requests.__url__              def __init__(self, url):                 self.url = url              def getAllUsers(self):     #the list is added here                 data = '''<ul class="users-list clearfix">                             <li>                               ...............                             </li>                                                   <li>                               ......                             </li>                             <li>                               .....                             </li>                           </ul>'''     # parsing the data to get text from list.             soup = BeautifulSoup('''data''', "html.parser")         user_names = soup.find('ul', class_='users-list clearfix')         split_details = list(user_names.stripped_strings)         print(split_details)         test = RESTApp("https://adminlte.io/themes/AdminLTE/pages/examples/profile.html")         test.getAllUsers()