unique fails

I have this little piece of code: ->unique( table: Sitemap::class, column: 'slug', ignoreRecord: true, ignorable: new Page) supposedly it keeps the same slug saved if I edit anything and I save it again, but it tells me that the slug already exists. Can anyone help or give a suggestion?
4 Replies
bernhard
bernhard12mo ago
what should ignorable: new Page do? and is the table really different from the Resource one?
joaoppcastro
joaoppcastroOP12mo ago
supposedly ignorable: new Page, ensures that the current Page model instance is ignored during the uniqueness validation of the specified column in the specified table and the table is the same Like this, you create a page and save it. then if you want to edit the page where you don't change the slug (like enter whether it is active or not or another field. as in the database the slug is the same it will say that it already exists This little code should prevent that, but it's not happening
bernhard
bernhard12mo ago
I understand what you try to achive, but the ignorable: new Pageis just useless. new Page create an empty instance of Page, which has no corresponding entry in the database ignorableis used if you want to ignore a specific record. For example ignoreable: Page::find(1) Doesn't just ->unique(ignoreRecord: true)work? Why do you need to provide the table ? Is it really another Model then the one from the current Ressource? And why column: 'slug'? Does your field have another name then slug?
joaoppcastro
joaoppcastroOP12mo ago
ignoreRecord: true doesn't work which was the first thing I tried Yes is another model, so I'm giving the name of the table and column to give SQL errors, which is what I was getting before with ignoreRecord: true The slug is in this resource, but when you save it it will be saved in another table Even when recording erases it and replaces it with the same one or another one if it is different
Want results from more Discord servers?
Add your server